PDA

View Full Version : PWM: Vernacular/Function (Newbee)



TerryN
- 2nd July 2008, 15:36
I note that PWM "Sample Code" examples:
http://www.melabs.com/resources/samples/pbp/767pwm.bas and
http://www.melabs.com/resources/samples/pbp/hardpwm.bas
both refer to using "Hardware PWM". Too, neither use the PWM or HPWM instruction.
Is "Hardware PWM" the same, then, as "Bit-Banging" PWM ...?
[Presumably "Bit-Banging PWM" can be done with (generally speaking) any output pin, and with (generally speaking) any uC, right?]
Does Hardware PWM simply mean the uC must have the 'hardware' to do PWM...and is that 'hardware' the CCP(s)?

My 16F737 has 3 Channels of CCP: I've seen examples that DO and DON'T use the PWM or HPWM. Should I be trying to use one of those instructions or not? (And Why?)

[My app: PWM Motor Control via opto-isolated MOSFETs].

Your patience apprecitated!

Charles Linquis
- 2nd July 2008, 15:58
You should decide whether or not a PWM frequency of 32,767Hz is fast enough for your application. That is the highest PWM frequency you can get with the PBP command "HWPWM" regardless of your oscillator frequency. If you need a PWM frequency higher than 32Khz, you need to write CCP1CON[4:5] and CCPR1L directly. You can get a PWM frequency of several hundred kilohertz that way - depending on your oscillator frequency and the number of bits of resolution you need.

HWPWM is not "bit banging". Bit banging usually involves sitting in a tight loop running software counters to do the PWM function - the PIC can't do anything else at that same time. HWPWM on the other hand, sets up the hardware to produce a PWM signal and your main program can go merrily on its way.

A third possible alternative is to use Darrel Taylor's PWM routine. It uses interrupts and counters to perform software (or bit-banging) PWM. The highest PWM frequency isn't very high, but this method can give you lots of channels of PWM without using 100% of your processor.

TerryN
- 3rd July 2008, 16:58
Very helpful post, Thank You.