View previous topic :: View next topic |
Author |
Message |
pat
Joined: 07 Sep 2003 Posts: 40 Location: Adelaide, Australia
|
PIC 18F452 PWM |
Posted: Tue Jan 25, 2005 7:56 pm |
|
|
Hi there,
I'm about to start using the 18F series for the first time, my first chip will be 18F452 in QFN44 package. To date I've only ever used 16F876. I only have an old version of PCM v3.168, so when my 18F hardware design is finished I'll probably purchase PCWH.
Anyway, to my question. There are two PWM outputs on the 18F452 on CCP1 and CCP2. The datasheet table 14-2 on pg 120 states that they both run at the same frequency becuase they both run off Timer-2. Am I misinterpreting this, and is it possible to run them at diff frequencies? I want to use one output to pulse a solenoid with PWM modulation (low frequencies around 100Hz-200Hz) and another output to modulate an LED brighness (much higher frequency, not sure but presume around a few kilohertz). This LED is actually the backlight on a LCD character module.
If diff freq for each PWM are not possible, should I just use the CCP1 PWM module for the LED brightness, and just use a timer interrupt and software to implement my own low freq PWM for the solenoid?
Are there any other gotchas with using 18F452 I should watch out for? I'm planning on using 8MHz crystal and using the 4x PLL clock multiplier.
Sorry for long post.
Thanks |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Tue Jan 25, 2005 8:53 pm |
|
|
Same frequencies for the PWM but you can use the modules in the compare mode and generate your own frequencies. Basically you get an int whenever the CCP value matches that of timer1 (or timer3 refer to the datasheet). There is even a special feature to toggle the output pin on match. |
|
|
pat
Joined: 07 Sep 2003 Posts: 40 Location: Adelaide, Australia
|
|
Posted: Tue Jan 25, 2005 10:00 pm |
|
|
Thanks that sounds ok. So the PWM module just saves a bit of coding and variable use compared to your suggestion? |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Wed Jan 26, 2005 7:10 am |
|
|
pat wrote: | Thanks that sounds ok. So the PWM module just saves a bit of coding and variable use compared to your suggestion? |
Depends on how you use the CCP. If set to toggle the output and you can get away with allowing the timer1 (or timer3) to run free then there is not really any extra software needed or interrupt. Everything is done in hardware. This of course would be for a 50% duty cycle. If you need to change the duty cycle, then you would need to change the ccp value on each interrupt. Not much code at all. |
|
|
Jerry I
Joined: 14 Sep 2003 Posts: 96 Location: Toronto, Ontario, Canada
|
|
Posted: Wed Jan 26, 2005 6:15 pm |
|
|
Quote:
Anyway, to my question. There are two PWM outputs on the 18F452 on CCP1 and CCP2. The datasheet table 14-2 on pg 120 states that they both run at the same frequency becuase they both run off Timer-2. Am I misinterpreting this, and is it possible to run them at diff frequencies? I want to use one output to pulse a solenoid with PWM modulation (low frequencies around 100Hz-200Hz) and another output to modulate an LED brighness (much higher frequency, not sure but presume around a few kilohertz). This LED is actually the backlight on a LCD character module.
The two output frequencies will be thw same. But I don't see it being very important to have the LED PWM to be any higher than 100-200Hz that is needed for output pulse for your solenoid. Any frequency over 60Hz to the LED, you will not see it flicker. What is important when changing the brightness is the ON and OFF time of the PWM output.
good luck |
|
|
pat
Joined: 07 Sep 2003 Posts: 40 Location: Adelaide, Australia
|
|
Posted: Wed Jan 26, 2005 6:48 pm |
|
|
Thanks, I will try running the LED dimmer at the low frequency.
Thanks also to Mark, I have some ideas to work with now.
Patrick |
|
|
|