I'm using systick interrupt of the MKL05Z32 every 100us to build a base time in my program like this.
So I hope I get the flag "flag.change" set every 200ms. This flag is declared inside a struct with many others like this:
unsigned char change:1;
I'm using this flag to change a pwm frequency. I want to use 2 frequencies and change each other every 200ms. So my code is:
TPM1_SC |= TPM_SC_TOF_MASK;
//Configure to frequency 1
//Configure to frequency 2
Unfortunately this is not working properly. It got this result:
Sometimes it seems the variable "flag.change" is not cleared in the FTM1 interrupt, leading to another frequency change in the next FTM1 interrupt. The strange thing is the waveforms change, thery are not periodic, meaning the strange behavior of flags.
I did many things to test and I saw when I changed the "flag.change" to a variable "flagChange" declared as unsigned char I got this:
The above figure is the result I expect to have. It is okay I know it is working this way, but I'm not satisfied because there are many others flags in structs and I want they work properly. So I would like to understand what is happening.
1-Variable "flag.change" and " step.pwm" are used only in these functions.
2-Variables are set every 200ms properly.
Any ideas will be appreciated. Thanks.