2010-10-12 11:42 PM
stm8s TIM1’s One Pulse Mode problem
2011-05-17 06:10 AM
Hi kadyrov,
Try to generate an update event before enabling counter. Hope that solves.TIM1_DeInit();
TIM1_TimeBaseInit(0, TIM1_COUNTERMODE_UP, 0xFF, 10);
TIM1_OC1Init(TIM1_OCMODE_PWM1, TIM1_OUTPUTSTATE_ENABLE, TIM1_OUTPUTNSTATE_DISABLE, 0x7F, TIM1_OCPOLARITY_LOW, TIM1_OCNPOLARITY_LOW, TIM1_OCIDLESTATE_RESET, TIM1_OCNIDLESTATE_RESET);
TIM1_SelectOnePulseMode(TIM1_OPMODE_SINGLE);
/* generate update event */
TIM1->EGR |= 0x01; /* or something like that */
TIM1_CtrlPWMOutputs(ENABLE);
TIM1_Cmd(ENABLE);
Tell me if it is OK. Regards, MCU Lüfter
2011-05-17 06:10 AM
Oh, problem is solved! Thanks lowpowermcu!
TIM1->EGR is set to 0x01 in TIM1_DeInit(), but then it is disabled in TIM1_OC1Init() for some reason. I set it by TIM1_GenerateEvent(TIM1_EVENTSOURCE_UPDATE) again and now Update Event occurs at the right moment. Here is fixed code:TIM1_DeInit();
TIM1_TimeBaseInit(0, TIM1_COUNTERMODE_UP, 0xFF, 10);
TIM1_OC1Init(TIM1_OCMODE_PWM1, TIM1_OUTPUTSTATE_ENABLE, TIM1_OUTPUTNSTATE_DISABLE, 0x7F, TIM1_OCPOLARITY_LOW, TIM1_OCNPOLARITY_LOW, TIM1_OCIDLESTATE_RESET, TIM1_OCNIDLESTATE_RESET);
TIM1_SelectOnePulseMode(TIM1_OPMODE_SINGLE);
TIM1_GenerateEvent(TIM1_EVENTSOURCE_UPDATE);
TIM1_CtrlPWMOutputs(ENABLE);
TIM1_Cmd(ENABLE);
Hi kadyrov,
Try to generate an update event before enabling counter. Hope that solves.TIM1_DeInit();
TIM1_TimeBaseInit(0, TIM1_COUNTERMODE_UP, 0xFF, 10);
TIM1_OC1Init(TIM1_OCMODE_PWM1, TIM1_OUTPUTSTATE_ENABLE, TIM1_OUTPUTNSTATE_DISABLE, 0x7F, TIM1_OCPOLARITY_LOW, TIM1_OCNPOLARITY_LOW, TIM1_OCIDLESTATE_RESET, TIM1_OCNIDLESTATE_RESET);
TIM1_SelectOnePulseMode(TIM1_OPMODE_SINGLE);
/* generate update event */
TIM1->EGR |= 0x01; /* or something like that */
TIM1_CtrlPWMOutputs(ENABLE);
TIM1_Cmd(ENABLE);
Tell me if it is OK. Regards, MCU Lüfter