PDA

View Full Version : Multiple PWM pins



Scampy
- 17th November 2013, 13:37
Hi

My current project uses an 18F4520 with two hardware PWM pins (C1 and C2) to drive two LED drivers so that the chains of LEDs can be ramped up and down. My code also uses an internal timer overflow to generate the clock so using software with pause statements is out of the question.

I've been doing some research to try and find a PIC that can provide more hardware PWM outputs and stumbled across the 18F4331 which seems to have dedicated 4 independent PWM outputs, which is primary used for motor control. I've looked at the datasheet but can not comprehend the information so wondered if one of you guys who understand these sheets can offer some advice. The data sheet can be found here http://ww1.microchip.com/downloads/en/DeviceDoc/39616d.pdf

Basically I need four independent PWM outputs where the duty cycle changes for each output (the frequency can be the same for each channel.

Currently I use the


hpwm 1,W_PWM,200
hpwm 2,B_PWM,200


Where W_PWM is the duty cycle to fade up the white LEDs and B_PWM the blues. This currently used the two CCP1 and CCP2 registers. Ideally I would like to have something like HPWM 3, and 4 in the code.

Would this work, or can the 18F4520 CCP registers be configured to give two more additional PWM outputs as the data sheet states the 18F4520 has "One, two or four PWM outputs". Again I'm assuming that four outputs are used for motor control where the duty cycle is identical for each output rather than being independent.

My settings for CCP registers are


CCP1CON = %00001100 'Set CCP1 to PWM
CCP2CON = %00001100 'Set CCP2 to PWM


I'd rather not post up my full code in the forum, but will send it via PM if required.

Any help would be most appreciated

Malcolm

HenrikOlsson
- 17th November 2013, 14:45
Hi,
The 4520 has 2 CCP modules so you can get two PWM-outputs, ie two PWM-signals with the same frequency but different dutycycle. The reference to "one, two or four outputs" probably refers to using the ECCP module in half or full bridge mode. Then the PWM signal "comes out" on multiple pins but it's still "the same" signal - basically.

The 2331 also has 2 CCP modules plus the PCPWM-module with 3 PWM generators (the 4331 has 4) so all in all, using the 2331, you can get 5 PWM outputs. Note that the HPWM command does not work for PCPWM module in the 2331, you'll have to configure it "manually".

If you don't need the extended features of the PCPWM module (which, by the sound of it you don't) then perhaps something like the 25K22 might work, it's a lot cheaper then the 2331. There are loads and loads of 18F series parts with 3 or more (E)CCP modules. I'm not entirely sure if the HPWM command supports more than 2 channels though but it's easy enough to configure the registers manually.

/Henrik.

Scampy
- 17th November 2013, 19:23
There are loads and loads of 18F series parts with 3 or more (E)CCP modules. I'm not entirely sure if the HPWM command supports more than 2 channels though but it's easy enough to configure the registers manually.

/Henrik.

After doing hours of googling, I stumbled across this post on a forum http://www.sonsivri.to/forum/index.php?topic=24131.0

Looking through his sample code it has



'PIC16F767 Device Controlling Red/White/Blue LED's
'Written July 2, 2009
'Copyright (c) PilotPTK
'U1 Main LED Driver


DEFINE OSC 20
ADCON1 = %10001101 'Port A0,A1 Analog, VREF+ = VDD, Right Justified Result
CCP1CON = %00001100 'CCP Setup (PWM Mode)
CCP2CON = %00001100 'CCP Setup (PWM Mode)
CCP3CON = %00001100 'CCP Setup (PWM Mode)


And then later down



HPWM 1,0,5000
HPWM 2,0,5000
HPWM 3,0,5000


So on that basis I would assume PBP's HPWM command support more than two channels.... so now to look for a chip that's 5v (as 3.3v is not supported on my development board) and has four ECCP modules, and then see if I can port the working code on the 18f4520 to it :)