This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCS/TMS570LC4357: Share of variable from the ISR (Interrupt Service Routine)

Part Number: TMS570LC4357

Tool/software: Code Composer Studio

Hello Everyone,

i have set a Het interrupt linked to a pwm that is triggered at every end of the period through a pwmNoification every 10 us. So every time i get my interrupt (everythink works properly on the hardware part) the pwm notification is also executed and inside my pwm notification i have initialized a counter (pwmCounter) which is reset at after 500 triggers. Now my pwmNotification function is initialized in my main.c and so is the variable pwmCounter (that should thus be a global variable). It is executed in the ISR which does not permit me to use a conditional if in my main.c to trigger another action let's when the pwmCounter is triggered 10 times for example. In order to check if i could apprecciate the change in the pwmCounter in my main.c i created a small if cycle and run the debug bu it nevers gets inside the conditional if cycle as if it could not read my variable pwmCounter changing in the ISR.

The project builds without errors so i do not believe it is a problem of includes.

Thank for your help

  • this is an imagine of the interrupt function in the het.c file

  • Hello,

    The code in pwmNotification() looks fine, and there is no problem with the code in the HET ISR. How many PWM channels are used? Please try lower PWM frequency to check if CPU handles the PWM interrupts all the time.

  • In fact my question was on how can i use the pwmCounter variable that i used in the ISR function in my main.c. It seems that the code does not read the variation of pwmCounter outside of the function pwmNotification. I need that variable to be global that is why i inizialed my pwmNotification function in my main.c and thus the variable pwmCounter too but it seems like the increase of this counter is only read in the ISR and is not shared throughput the whole c project as it should.

  • I understood. If you have many PWM channels which generate PWM signals with high frequency, the CPU spends its 100% bandwidth to handle the interrupts and doesn't execute the if-condition code in your main(). This is why I asked you to try lower PWM frequency and less PWM channels.

    Check the disassembly code to make sure the if() is not affected by the code optimization.

  • i had only one pwm the problem was that my counter variable was not declared as a volatile variable and so the changes that happened in the ISR were not read in the main.c file. I had also to create a support variable to that counter because its initialization was done in the main.c file and so it was always read as 0 ( initial value). Thank you anyway for your prompt help i will keep in mind the precautions you pointed out when working with multiple pwm's.

    Thanks and Regards