PIC24F: Cleanly terminating PWM trains

Thread Starter


Joined Jan 5, 2016
Hi. Hopefully there's a best practice here that I'm not aware of. I'm using OC1 and OC2 on a PIC24F to drive a boost converter.
  • OC1 drives the lowside, is in edge-aligned mode, and is self-sync'ed. OC1R~10us, OC1RS~100us (period).
  • OC2 drives the highside, is in centre-aligned mode, and is sync'ed with OC1. OC2R~11us, OC2RS~90us
What's the cleanest way to terminate the pulse train after the current cycle has run thru? Currently I'm disabling the module by setting OCM=0 and then manually setting the OC1 and OC2 pins to 0 which is very messy in code and stops the pulse train at a random point. Perhaps something like setting OC1R=0 would effectively turn off OC1 after the current pulse train has run thru, but would that also stop OC2?

Any advice appreciated.