Creating PWM on Interrupt from Zero Cross Detector

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
AmMa_2724956
Level 2
Level 2
First like received

Hello,

I want to write PWM when we get Interrupt, which is connected to ZCD.

Please provide any method for doing this.

Thanks in Advance.

0 Likes
1 Solution
Anonymous
Not applicable

Upon interrupt, set a flag.

Check the flag in main, and when it gets set, clear it, then turn on the PWM with PWM_Start().

If you want to change the PWM settings, then you will want to call PWM_Init() with the settings when you want to change them.

The API will change based on which PWM implementation you used, but something similar to the following should work:

At startup:

     TCPWM_Init();

In ISR:

     PWM_Start_Flag = true;

In Main:

     if(PWM_Start_Flag) {

          PWM_Start_Flag = false;

          if(TCPWM_ReadStatus() != STATUS_RUNNING) {

               TCPWM_Start();

          }

     }

View solution in original post

0 Likes
1 Reply
Anonymous
Not applicable

Upon interrupt, set a flag.

Check the flag in main, and when it gets set, clear it, then turn on the PWM with PWM_Start().

If you want to change the PWM settings, then you will want to call PWM_Init() with the settings when you want to change them.

The API will change based on which PWM implementation you used, but something similar to the following should work:

At startup:

     TCPWM_Init();

In ISR:

     PWM_Start_Flag = true;

In Main:

     if(PWM_Start_Flag) {

          PWM_Start_Flag = false;

          if(TCPWM_ReadStatus() != STATUS_RUNNING) {

               TCPWM_Start();

          }

     }

0 Likes