Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Measuring 3 Channel PWM Signal

Status
Not open for further replies.

Knife

Member level 2
Member level 2
Joined
Apr 26, 2009
Messages
43
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Visit site
Activity points
1,593
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 ?

Code:
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);
    }
}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top