PDA

View Full Version : Zero crossing output with HWPM



bradhartmann
- 5th December 2007, 21:57
I will be using the HWPM command on my PIC18F8722 and I need to pulse an output on the zero crossing of the sine wave, and also at the max value of the sine wave to synchronize an external device to it. How do I do this?

sougata
- 6th December 2007, 04:48
Hi,

As you mentioned you need a pulse does that mean you need to modulate your hardware PWM. If the criteria is limited to a pulse only then you may not need the Hardware PWM cause depending on the PWM frequency and duty cycle your PIC would be throwing a series of pulses while you start or stop your PWM.

One approach could be :

1. Measure the width (time period) of your input sinewave using a 16 bit timer
2. Using the same timer in the next cycle (or consecutive cycle) to run upto half the value captured and fire an ouput (using the CCP module compare feature)
3. Using the sine zero cross on an External INT to deal with the pulse output you need.

bradhartmann
- 6th December 2007, 15:26
The PWM will be normal but I want to fire separate digital outputs at zero crossing and max to sync up an external device.

Is there a way to access the PWM registers directly, so I can fire these outputs based on their value?

sougata
- 6th December 2007, 15:51
Hi,

In PBP all (almost) the registers of the PIC MCU are accessible. The 2 LSB of the PWM are in the CCPCON(CCP1CON/CCP2CON) bit 5,4. The MSBs are directly accessible using the CCPR1L and CCPR2L.

bradhartmann
- 6th December 2007, 19:17
Exactly what I was looking for. Thank you