cancel
Showing results for 
Search instead for 
Did you mean: 

Measuring 3 Channel PWM Signal

idurgun
Associate
Posted on March 04, 2014 at 09:00

Hi All

I want to measure PWM output of RGB controller with STM8S105 @16Mhz internal oscillator. The PWM signals are phase align and PWM signal frequency is 500 Hz.. PWM signal duty is changing between 0% and 100%. System start 0%, 100% or any value between 0% and 100%. I connected TIM1 Channel1 and Channel2 to Red_PWM, TIM1 Channel3 and Channel 4 to Green_PWM channels. I can catch all values when I apply a input PWM. If I apply second or third channel or all of them, I can not catch 2-3% PWM each channel. I read random variables. I think that is cause from resetting TIM1 counter (TIM1_SetCounter(0x00);) but I didn't handle. Could anyone suggest a solution ?

INTERRUPT_HANDLER(TIM1_CAP_COM_IRQHandler, 12)
{
/* In order to detect unexpected events during development,
it is recommended to set a breakpoint on the following instruction.
*/
if((TIM1->SR1 & TIM1_FLAG_CC1) == TIM1_FLAG_CC1)
{
TIM1_ClearFlag(TIM1_FLAG_CC1);
if(bCapture1_Rising == FALSE)
{
bCapture_Timer_Reset = TRUE;
bCapture1_Rising = TRUE;
}
else
{
wRed_Period = TIM1_GetCapture1();
wRed_PWM = (100 * (DWORD)wRed_On_Time) / wRed_Period;
bCapture_Timer_Reset = TRUE;
wRed_OVF_Flag = 0;
}
}
if((TIM1->SR1 & TIM1_FLAG_CC2) == TIM1_FLAG_CC2)
{
TIM1_ClearFlag(TIM1_FLAG_CC2);
wRed_On_Time = TIM1_GetCapture2();
}
if((TIM1->SR1 & TIM1_FLAG_CC3) == TIM1_FLAG_CC3)
{
TIM1_ClearFlag(TIM1_FLAG_CC3);
if(bCapture2_Rising == FALSE)
{
bCapture_Timer_Reset = TRUE;
bCapture2_Rising = TRUE;
}
else
{
wGreen_Period = TIM1_GetCapture3();
wGreen_PWM = (100 * (DWORD)wGreen_On_Time) / wGreen_Period;
bCapture_Timer_Reset = TRUE;
}
}
if((TIM1->SR1 & TIM1_FLAG_CC4) == TIM1_FLAG_CC4)
{
TIM1_ClearFlag(TIM1_FLAG_CC4);
wGreen_On_Time = TIM1_GetCapture4();
} 
if(bCapture_Timer_Reset == TRUE)
{
bCapture_Timer_Reset = FALSE;
TIM1_SetCounter(0x00);
}
}

#capture-pwm #stm8s105 #pwm
1 REPLY 1
DAS.ANIL KUMAR
Associate II
Posted on June 24, 2014 at 05:27

i am using 16 Mhz internal freq.  i am generating  both signal with 10us for on and 8 us for off and continue in TIMER1 CH3 AND CH4  and i want to 1 us second delay between these signal  or 2nd signal start after 1us and continue.

plz help me   thanks