完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
你好社区,
我尝试为我的实验编写代码,我有一个问题..我的代码应该改变占空比即。如果Convertion_Value_Current的值超过或低于特定值,则CCR2_V的值...因此我希望在示波器上看到一个变化的pwm,但它仍然具有与主要定义的相同的占空比(CCR2_V = 27) 这个想法是增加或减少寄存器的值,但它不起作用。你有什么想法可以解决问题吗? 谢谢 BG &amp; sharpinclude&lt; stm8s.h&gt; &amp; sharpinclude&lt; stm8s_eval_lcd.h&gt; &amp; sharpinclude&lt; stdio.h&gt; uint8_t StrName [16] = {0}; uint16_t Conversion_Value = 0; float Stufe = 0.00488; float Nominal_Min = 3.500; float Nominal_Max = 4.500; float Conversion_Value_Current = 0; uint16_t CCR2_Val = 27; uint8_t a = 50; // Parametrisierung des PI Reglers !!!! MUSS NOCH在matlab BESTIMMT WERDEN !!!! // float kp = 0.001; float tn = 0.04; int main(void){ // Systemtakt CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1); // Erzeuge PWM TIM3_DeInit(); TIM3_TimeBaseInit(TIM3_PRESCALER_1,45); TIM3_OC2Init(TIM3_OCMODE_PWM1,TIM3_OUTPUTSTATE_ENABLE,CCR2_Val,TIM3_OCPOLARITY_HIGH); TIM3_ARRPreloadConfig(ENABLE); TIM3_OC2PreloadConfig(ENABLE); TIM3_Cmd(ENABLE); // Initialisiere ADC和LCD STM8S_EVAL_LCD_Init(); GPIO_DeInit(GPIOB); ADC2_DeInit(); GPIO_Init(GPIOB,GPIO_PIN_2,GPIO_MODE_IN_PU_NO_IT); ADC2_Init(ADC2_CONVERSIONMODE_CONTINUOUS,ADC2_CHANNEL_2,ADC2_PRESSEL_FCPU_D4,ADC2_EXTTRIG_TIM,DISABLE,ADC2_ALIGN_RIGHT,ADC2_SCHMITTTRIG_CHANNEL9,DISABLE); ADC2_Cmd(ENABLE); LCD_Clear(); LCD_BacklightCmd(ENABLE); ADC2_StartConversion(); LCD_SetCursorPos(LCD_LINE1,0); LCD_Print( 'Convers.Value .:'); LCD_Print(''); 而(1) { 而(!ADC2_GetFlagStatus()){} Conversion_Value = ADC2_GetConversionValue(); Conversion_Value_Current = Conversion_Value * Stufe; // Regelung der DutyCyclef reinenerw nschtenAusgangsstrom if(Conversion_Value_Current&gt; Nominal_Max) { CCR2_Val--; } 否则if(Conversion_Value_Current&lt; Nominal_Min) { CCR2_Val ++; } TIM3_OC2Init(TIM3_OCMODE_PWM1,TIM3_OUTPUTSTATE_ENABLE,CCR2_Val,TIM3_OCPOLARITY_HIGH); sprintf((char *)StrName,'%。3f',(Conversion_Value * Stufe)); LCD_SetCursorPos(LCD_LINE2,0); LCD_Print(则strName); ADC2_ClearFlag(); } } #stm8 / 128#pwm-stm8#stm8 以上来自于谷歌翻译 以下为原文 Hello community, i try to programm an code for my experimentation and i have a problem .. my code should change the duty cycle ie. the value of CCR2_V if the value of Convertion_Value_Current exceeds or is below a specific value .. as a result i want to see on the oscilloscope a changing pwm but it is still with the same duty cycle as defined in the main (CCR2_V=27) the idea was to increment or decrement the value of the register, but it does not working. Have you any ideas where the problem can be? Thanks BG &sharpinclude &sharpinclude &sharpinclude uint8_t StrName[16]={0}; uint16_t Conversion_Value = 0; float Stufe = 0.00488; float Nominal_Min = 3.500; float Nominal_Max = 4.500; float Conversion_Value_Current = 0; uint16_t CCR2_Val = 27 ; uint8_t a = 50; // Parametrisierung des PI Reglers !!!! MUSS NOCH IN MATLAB BESTIMMT WERDEN !!!! // float kp = 0.001; float tn = 0.04;int main(void){ // Systemtakt CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1); // Erzeuge PWM TIM3_DeInit(); TIM3_TimeBaseInit(TIM3_PRESCALER_1, 45); TIM3_OC2Init(TIM3_OCMODE_PWM1, TIM3_OUTPUTSTATE_ENABLE,CCR2_Val, TIM3_OCPOLARITY_HIGH); TIM3_ARRPreloadConfig(ENABLE); TIM3_OC2PreloadConfig(ENABLE); TIM3_Cmd(ENABLE); // Initialisiere ADC und LCD STM8S_EVAL_LCD_Init(); GPIO_DeInit(GPIOB); ADC2_DeInit(); GPIO_Init(GPIOB, GPIO_PIN_2, GPIO_MODE_IN_PU_NO_IT); ADC2_Init(ADC2_CONVERSIONMODE_CONTINUOUS, ADC2_CHANNEL_2, ADC2_PRESSEL_FCPU_D4, ADC2_EXTTRIG_TIM, DISABLE , ADC2_ALIGN_RIGHT, ADC2_SCHMITTTRIG_CHANNEL9, DISABLE); ADC2_Cmd(ENABLE); LCD_Clear(); LCD_BacklightCmd(ENABLE); ADC2_StartConversion(); LCD_SetCursorPos(LCD_LINE1, 0); LCD_Print('Convers.Value.:'); LCD_Print(' '); while(1) { while(!ADC2_GetFlagStatus()){} Conversion_Value = ADC2_GetConversionValue(); Conversion_Value_Current = Conversion_Value*Stufe; //Regelung der Duty Cycle f�r einen erw�nschten Ausgangsstrom if(Conversion_Value_Current > Nominal_Max) { CCR2_Val--; } else if (Conversion_Value_Current < Nominal_Min) { CCR2_Val++; } TIM3_OC2Init(TIM3_OCMODE_PWM1, TIM3_OUTPUTSTATE_ENABLE,CCR2_Val, TIM3_OCPOLARITY_HIGH); sprintf((char*)StrName, '%.3f ', (Conversion_Value*Stufe)); LCD_SetCursorPos(LCD_LINE2, 0); LCD_Print(StrName); ADC2_ClearFlag(); } } #stm8/128 #pwm-stm8 #stm8 |
|
相关推荐
2个回答
|
|
可能会避免预加载CCRx,而是让新值锁定在更新事件。
以上来自于谷歌翻译 以下为原文 Would probably avoid preloading the CCRx, but rather let the new value latch at the update event. |
|
|
|
Hello Clive One,非常感谢您的快速回复和支持。
但是,当我没有预加载CCR2,那么我没有波形..慢速吸收,对不起,我不打算得到它 如何在代码中缓冲新值? 以上来自于谷歌翻译 以下为原文 Hello Clive One, thanks a lot for your fast reply and support. But when I do not preload the CCR2, then i do not have the waveform .. slow on the uptake, sorry i do not quire get it How the buffering the new value would be look like in the code? |
|
|
|
只有小组成员才能发言,加入小组>>
请教:在使用UDE STK时,单片机使用SPC560D30L1,在配置文件怎么设置或选择?里面只有SPC560D40的选项
2747 浏览 1 评论
3244 浏览 1 评论
请问是否有通过UART连接的两个微处理器之间实现双向值交换的方法?
1813 浏览 1 评论
3655 浏览 6 评论
6045 浏览 21 评论
1342浏览 4评论
204浏览 3评论
对H747I-DISCO写程序时将CN2的st-link复用为usart1,再次烧录时无法检测到stlink怎么解决?
359浏览 2评论
STM32G474RE芯片只是串口发个数据就发烫严重是怎么回事?
451浏览 2评论
STM32处理增量式编码器Z信号如何判断中断是正转的还是反向转的?
277浏览 2评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-30 03:01 , Processed in 1.094025 second(s), Total 50, Slave 44 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号