I'm trying to create interrupt ~235 Hz to dim some LED's. ( I use both edges of timer1 output to get the 235Hz)
I'm using Timer1 as a 50% PWM signal to create the above.
I'm actually getting a 53.6% dutycycle as measured on the LED pin. For my application this is not critical but I would like to understand where I went wrong (I assume its NOT the timer1 bug).
What you are doing is not a timer PWM mode. In PWM mode, the timer itself switches the state of the output pin without using interrupts.
Interrupt entry and exit takes time, so your method cannot give accurate intervals.
In your case, it is generally not clear why do you need timers and interrupts. Your code is completely equivalent to the usual blink code in a loop()
Your code also blocks the whole program like any code with delays. More precisely, your code is even worse - unlike the code in the main program, your code also blocks system interrupts
That picture doesn't seem to match your code. It looks like the falling transition of the bottom trace is happening at the END of the seven pulses generated in the ISR. According to the code the LED pin transitions first, then the pulses are generated.
The second falling transition is showing up in the middle of the pulses?!?
Thanks, I'll look closer at how the measurements are made
Update, I see what you mean Thank you for your observation and time to look at my code.
I'm somewhat embarrassed that I missed this
I upped the sample rate of the Logic analyzer and not ALL transitions look wrong. Before some looked right.
Its time to get out the oscilloscope and see what is really going on.
Again thank you for your observation. I found I had not set the LED pin to an output. I've done this before so I'll have to put a note on the wall to always check this first.
What also threw me was the LED was working. It seems if you don't declare it as an output the Pin will go high then go open or "kinda" low which delayed the analyzer trigger.