View previous topic :: View next topic |
Author |
Message |
Johnson Kao Guest
|
How to generate two PWM from PIC18F452 |
Posted: Sun Dec 23, 2007 3:44 pm |
|
|
Dear All,
I will generate two PWM from PIC18F452. The two signal will be push-pull within a deadtime. Have anyone know how to do? I have tried many times but all failed. Have any sample code for reference? Thanks a lot,
Johnson |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Dec 23, 2007 4:45 pm |
|
|
This post shows how to do simple dual PWM using the CCP modules.
http://www.ccsinfo.com/forum/viewtopic.php?t=17729&start=1
However, that's not what you want to do.
Quote: | The two signal will be push-pull within a deadtime. |
I think you need a PIC with an ECCP module. I suggest that you
get an 18F4520. It's similar to the 18F452, except that it has an ECCP
with these features:
Quote: |
Enhanced Capture/Compare/PWM (ECCP) module:
- One, two or four PWM outputs
--- Single Output
--- Half-Bridge Output
--- Full-Bridge Output, Forward mode
--- Full-Bridge Output, Reverse mode
- Selectable polarity
- Programmable dead time
- Auto-Shutdown and Auto-Restart |
|
|
|
John P
Joined: 17 Sep 2003 Posts: 331
|
|
Posted: Sun Dec 23, 2007 7:44 pm |
|
|
It all depends on the frequency of the waves you want to generate, and the resolution of the PWM outputs. It could be an easy project, or just plain impossible. You'll have to explain more. |
|
|
Guest
|
|
Posted: Mon Dec 24, 2007 10:04 am |
|
|
John P wrote: | It all depends on the frequency of the waves you want to generate, and the resolution of the PWM outputs. It could be an easy project, or just plain impossible. You'll have to explain more. |
Thanks for all reply.
More describe about my requirement, I will generate two pwm signal(push-pull) and both of frequency are 50Khz(external XTAL=20MHz).
Any information need to provide? |
|
|
John P
Joined: 17 Sep 2003 Posts: 331
|
|
Posted: Mon Dec 24, 2007 10:45 am |
|
|
Maybe I wasn't clear about what's needed to understand the requirements. By "resolution" I meant how many different pulse widths need to be produced, potentially.
For instance, you're saying that the period of the output signal, at 50KHz, must be 20usec. So would it be acceptable to have the ability to produce 11 different outputs, at 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, or 20 usec (where 0 and 20 would be "always off" or "always on")? I'd call that "10% resolution"; if it's not acceptable, what would you need?
Also, will the chip have to do anything else while this runs, such as servicing interrupts? Communication of any kind?
I'm thinking that there might be a minimal way to do this, by setting up a loop outside of any interrupts which simply decrements a counter and flips external port pins at the right times. But it won't be able to keep doing that and service interrupts or do much of anything else at the same time unless you can tolerate disruptions in the output waveform.
And if a change in duty cycle is called for, is irregularity in the waveform acceptable for one (or a few) cycles a during the transition? |
|
|
Johnson Kao Guest
|
|
Posted: Tue Dec 25, 2007 11:49 am |
|
|
Resolution is 40%.
Thanks a lot, |
|
|
John P
Joined: 17 Sep 2003 Posts: 331
|
|
Posted: Fri Dec 28, 2007 2:45 pm |
|
|
You're not providing enough information to know if this can be done or not.
Also, is it a class project? If so, I think you need to figure it out for yourself. |
|
|
Guest
|
|
Posted: Fri Jan 18, 2008 2:46 pm |
|
|
for example? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Jan 18, 2008 5:07 pm |
|
|
There are many projects posted on the internet, that show how to use
a PIC to drive a motor. Do a search with http://www.google.com for
Here is one of the projects:
http://hades.mech.northwestern.edu/wiki/index.php/PIC_PWM_Motor_Driver
He uses a PIC that has built-in motor-driver features in the PWM module.
He connects the PWM outputs of the PIC to a push-pull driver chip.
The schematic in the L293B data sheet shows how to connect it to a
motor. So does the link above.
http://www.st.com/stonline/books/pdf/docs/1328.pdf
I suggest that you buy one of many PICs that have a built-in motor
driver module (it's part of the PWM module). Then the project will be
very easy. The PIC that he uses (16F684) is extremely cheap.
Digikey sells it for only 2.63(USD) for quantity 1 in the DIP package.
http://www.digikey.com |
|
|
|