Revisit - Timer PWM vs Millis

Hi Guys,
This is in reference to a previous thread I started:

I had incredible help from several guys, including @Johnwasser and @cattledog. And through their assistance I managed to complete the project.

There were some minor issues with using mode 14 Fast PWM which were brought up by cattle dog regarding a one clock cycle toggle of the pins when the PWM went from TOP to BOTTOM. He also suggested that the "conditioning of the signal" would probably get rid of these spikes, which it did, but yesterday while playing with it again I found a new button on my oscilloscope (Peak Detect) which plainly showed these toggles. Wow. Wasn't ready for that.

Anyway, he also suggested using mode 8 Phase and Frequency Correct PWM to fix this problem and offered some code, which upon trying, didn't work from the off. So I went back to basics, broke out the data sheet and spent a couple of hours playing with this mode 8 PWM, and once I was comfortable with it, I went back to my code, made a few changes and BINGO!! It worked perfectly and those offending spikes were gone.

So really, this post is just to say another huge thanks to all you guys that offered your vast knowledge to help me out.

On the flipside, I still have a little problem with the electronic components side of things but I'm trying to figure that out. The PWM side of things is 100% perfect, but for some reason with the signal conditioning I'm getting a very slow slew rate out of my opamp. Hey ho. The thing still does what it's supposed to do so that slow signal rise isn't a big problem it would seem, but just a little niggle I'm having.

Happy to post the final code up if anyone is interested.

All the best.

Matt

1 Like

You could use the solution that analogWrite() uses: If the PWM value is BOTTOM, turn off PWM and set the pin LOW. If the PWM value is TOP, turn off PWM and set the pin HIGH. Otherwise, make sure PWM is enabled and set the OCR.

Thanks @johnwasser I'll give that a try. I see in the Arduino core that it just sets the pin LOW or HIGH depending if the value is 0 or 255.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.