|
|
View previous topic :: View next topic |
Author |
Message |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Aug 04, 2009 3:36 pm |
|
|
I don't have your PIC, but I do have an 18F4620. It also has an ECCP
module for CCP1, and a normal PWM module for CCP2. The following
program shows how to setup both CCP modules for normal PWM.
Code: |
#include <18F4620.h>
#fuses XT,NOWDT,PUT,BROWNOUT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
//=================================
void main()
{
// Setup for 3.9 KHz pwm frequency with 4 MHz oscillator.
setup_timer_2(T2_DIV_BY_1, 255, 1);
// Setup the ECCP for PWM in normal mode on Pin C2.
setup_ccp1(CCP_PWM);
set_pwm1_duty(100); // 40% duty cycle
// Setup CCP2 for PWM output on pin C1.
setup_ccp2(CCP_PWM);
set_pwm2_duty(50); // 20 % duty cycle
while(1);
} |
|
|
|
Ringo42
Joined: 07 May 2004 Posts: 263
|
|
Posted: Tue Aug 04, 2009 3:52 pm |
|
|
Cool thanks, That is what I was hoping for.
Ringo _________________ Ringo Davis |
|
|
Ttelmah Guest
|
|
Posted: Wed Aug 05, 2009 3:07 am |
|
|
It is also worth looking at the data sheet 'again'.
If you look at the section for the CCP, you get the line:
"PIC18F4585/4680 devices have two CCP1
(Capture/Compare/PWM) modules. CCP1, discussed in
this chapter, implements standard Capture, Compare
and Pulse-Width Modulation (PWM) modes.
ECCP1 implements an Enhanced PWM mode. The
ECCP1 implementation is discussed in Section 16.0
“Enhanced Capture/Compare/PWM (ECCP1)
Module”."
Then at the start of the ECCP section, you get:
"Capture,
Compare and single output PWM functions of the
ECCP1 module are the same as described for the
standard CCP1 module."
I must admit, the early MicroChip data sheets were far superior to the current offerings, in terms of clarity, but If you look at the above, and think about what it is saying, you have two modules, one CCP, and one ECCP. The standard operating modes of the ECCP module, are identical to a CCP, but then it has the 'extra' modes 'on top'.
Best Wishes |
|
|
Ringo42
Joined: 07 May 2004 Posts: 263
|
|
Posted: Wed Aug 05, 2009 7:32 am |
|
|
It was the line
"Compare and single output PWM functions of the
ECCP1 module are the same as described for the
standard CCP1 module."
That gave me doubts. When it said "Same as" I did not know if that meant it was one or the other.
Also, how to use it with the compiler was another question. But now I see that you use it like it was a second CCP.
Ringo _________________ Ringo Davis |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|