2009-08-03 07:17 AM
STM32 - Servo Board (RC Servos)
2011-05-17 04:19 AM
Hello Togehter,
I just make the step from AVR to powerfull STM32 and need to controll a servo. Timer for the STM32 are for me very confused, so my question, has somebody already made a servo board, like this Every 20ms a Signal with lenght from 0.9 (hard left) to 2.1ms (hard right) Thank you very mutch. Best Regards Askan2011-05-17 04:19 AM
Hello Togehter,
ok, here is my current codeCode:
volatile s32 myTimerCounter1 = 0; void TIM2_IRQHandler(void) { // Also cleared the wrong interrupt flag in the ISR TIM_ClearFlag(TIM2, TIM_FLAG_Update); // TIM_GetITStatus(TIM2, TIM_IT_CC1) != RESET TIM_ClearITPendingBit(TIM2, TIM_IT_CC1); // Clear the interrupt flag //TIM2->CCR1 = 20; myTimerCounter1++; } //------ // Description : Initialize the Timer2 channel-1. // TIM2CLK = 36 MHz, counter clock = 20 ms TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; TIM_OCInitTypeDef TIM_OCInitStructure; TIM_TimeBaseStructure.TIM_Period = 32000; // auto reaload register TIM_TimeBaseStructure.TIM_Prescaler = 0; TIM_TimeBaseStructure.TIM_ClockDivision = 0; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure); TIM_PrescalerConfig(TIM2, 19, TIM_PSCReloadMode_Immediate); TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Timing ; TIM_OCInitStructure.TIM_OutputState = TIM_Channel_1; TIM_OCInitStructure.TIM_Pulse = 0; TIM_OC1Init(TIM2, &TIM_OCInitStructure); TIM_OC1PreloadConfig(TIM2, TIM_OCPreload_Disable); TIM_ClearFlag(TIM2, TIM_FLAG_Update); TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE); TIM_ClearFlag(TIM2, TIM_FLAG_Update); TIM_Cmd(TIM2, ENABLE); while (1) { // Zusammen 1 Sekunde... Delay(250); LED2_OFF(); Delay(250); LED2_ON(); Delay(250); LED2_OFF(); Delay(250); LED2_ON(); rprintf(''Result: %dr'', myTimerCounter1); } The timer runs successfully with 20ms, so I try to use OutputCompare to generate some Signal's (PIN_X On, PIN_X Off etc.) In Timer TIM2_IRQHandler, I set this,Code:
TIM2->CCR1 = 20; so the the timer should generate mutch more Interrupts, but nothing happend. Please help. It would be great if anybody has an idea. Thank you very mutch & Best Regards Askan2011-05-17 04:19 AM
Hello,
I just make my first steps with STM32 Timer, I have setup a mini timerQuote:
volatile s32 myTimerCounter = 0; void TIM2_IRQHandler(void) { myTimerCounter++; } int main(void) { // Initalisieren, STM32_Init, GPIO, UART ... // TIM2CLK = 32 MHz, Prescaler = 100, TIM2 counter clock = 32 KHz TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; //TIM_TimeBaseStructure.TIM_Period = 0; TIM_TimeBaseStructure.TIM_Prescaler = 100; TIM_TimeBaseStructure.TIM_ClockDivision = 0; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure); TIM_Cmd(TIM2, ENABLE); while (1) { Delay(250); LED2_OFF(); Delay(250); LED2_ON(); rprintf(''Stand2: %d\r'', myTimerCounter); } } Result is: Stand2: 0 Stand2: 0 Stand2: 0 Stand2: 0 I think there is something missing or wrong, because the handler ist never called. If anybody has an idea, how to solve the problem, thank you very mutch. Best Regard from Germany Askan2011-05-17 04:19 AM
Hello Togehter,
I try also to code the Timer without the Libary.Code:
<BR>void TIM2_IRQHandler (void) { <BR> <BR> <BR>} <BR> <BR>int main(void) { <BR> <BR> <BR> <BR> while (1) { <BR> // Zusammen 1 Sekunde... <BR> Delay(250); <BR> LED2_OFF(); <BR> Delay(250); <BR> LED2_ON(); <BR> Delay(250); <BR> LED2_OFF(); <BR> Delay(250); <BR> LED2_ON(); <BR> <BR> static s8 toggle = 1; <BR> <BR> <BR> <BR> rprintf(''Result: %dr'', myTimerCounter1); <BR> myTimerCounter1 = 0; <BR> } <BR> <BR> <BR>
But the Result is always nearly same, with the different CCR1 there should be a big difference. Please help... Thank you very mutch Askan [ This message was edited by: askansimon on 14-01-2010 21:03 ]2011-05-17 04:19 AM
Quote:
But the Result is always nearly same, with the different CCR1 there should be a big difference. Why? It seems you have enabled the Update interrupt which will fire every 20 ms and apparently does so. You have no interrupts related to compare/capture channel 1 enabled, as far as I can see. Even if you had, how would changing CCR1 affect the interrupt frequency? You're not resetting the counter on compare match.2011-05-17 04:19 AM
Hello,
thank you very mutch, now it's workingQuote:
void TIM2_IRQHandler (void) { // Interrupt Flag' muß per Software gelöscht werden myTimerCounter1++; } int main(void) { // ++ Initalisieren while (1) { // Zusammen 1 Sekunde... Delay(250); LED2_OFF(); Delay(250); LED2_ON(); Delay(250); LED2_OFF(); Delay(250); LED2_ON(); static s8 toggle = 1; if (toggle) { toggle = 0; TIM2->CCR1 = 10; } else { toggle = 1; TIM2->CCR1 = 15000; } rprintf(''Result: %d\r'', myTimerCounter1); myTimerCounter1 = 0; } [ This message was edited by: askansimon on 14-01-2010 21:03 ]