|
|
View previous topic :: View next topic |
Author |
Message |
Ringo Guest
|
PWM |
Posted: Tue Jan 15, 2002 12:18 pm |
|
|
IS it possible to set up 2 different PWM signals on a pic 16f877?
Tha data sheet says 2 capture/compare/pwm modules, but any example I have found only use 1.
I know to use:
setup_ccp1(CCP_PWM)
setup_timer_2(T2_DIV_BY_1, 127, 1);
set_pwm1_duty(value);
for the first pwm, but what "setup_timer" do I use for the 2nd pwm?
Thanks
___________________________
This message was ported from CCS's old forum
Original Post ID: 2005 |
|
|
Neutone
Joined: 08 Sep 2003 Posts: 839 Location: Houston
|
Re: PWM |
Posted: Tue Jan 15, 2002 12:30 pm |
|
|
This is from the device file for the 16f877
////////////////////////////////////////////////////////////////// CCP
// CCP Functions: SETUP_CCPx, SET_PWMx_DUTY
// CCP Variables: CCP_x, CCP_x_LOW, CCP_x_HIGH
// Constants used for SETUP_CCPx() are:
#define CCP_OFF 0
#define CCP_CAPTURE_FE 4
#define CCP_CAPTURE_RE 5
#define CCP_CAPTURE_DIV_4 6
#define CCP_CAPTURE_DIV_16 7
#define CCP_COMPARE_SET_ON_MATCH 8
#define CCP_COMPARE_CLR_ON_MATCH 9
#define CCP_COMPARE_INT 0xA
#define CCP_COMPARE_RESET_TIMER 0xB
#define CCP_PWM 0xC
#define CCP_PWM_PLUS_1 0x1c
#define CCP_PWM_PLUS_2 0x2c
#define CCP_PWM_PLUS_3 0x3c
long CCP_1;
#byte CCP_1 = 0x15
#byte CCP_1_LOW= 0x15
#byte CCP_1_HIGH= 0x16
long CCP_2;
#byte CCP_2 = 0x1B
#byte CCP_2_LOW= 0x1B
#byte CCP_2_HIGH= 0x1C
:=IS it possible to set up 2 different PWM signals on a pic 16f877?
:=Tha data sheet says 2 capture/compare/pwm modules, but any example I have found only use 1.
:=I know to use:
:=setup_ccp1(CCP_PWM)
:=setup_timer_2(T2_DIV_BY_1, 127, 1);
:=set_pwm1_duty(value);
:=
:=for the first pwm, but what "setup_timer" do I use for the 2nd pwm?
:=Thanks
___________________________
This message was ported from CCS's old forum
Original Post ID: 2006 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
Re: PWM |
Posted: Tue Jan 15, 2002 2:01 pm |
|
|
:=IS it possible to set up 2 different PWM signals on a pic 16f877?
:=Tha data sheet says 2 capture/compare/pwm modules, but any example I have found only use 1.
:=I know to use:
:=setup_ccp1(CCP_PWM)
:=setup_timer_2(T2_DIV_BY_1, 127, 1);
:=set_pwm1_duty(value);
:=
:=for the first pwm, but what "setup_timer" do I use for the 2nd pwm?
Both PWMs use Timer2. Therefore, they both must have the
same frequency. Each one can have a different duty cycle.
setup_ccp1(CCP_PWM);
setup_ccp2(CCP_PWM);
setup_timer_2(T2_DIV_BY_1, 127, 1);
set_pwm1_duty(value1);
set_pwm2_duty(value2);
___________________________
This message was ported from CCS's old forum
Original Post ID: 2010 |
|
|
sobak Guest
|
PWM problem |
Posted: Thu Nov 04, 2004 4:26 am |
|
|
I'm trying to produce %50 duty cycle pwm output from RC1/CCP2 on PIC18F8720 and I can do it, I can see with oscilloscope.
but,
when I do that
setup_ccp2(CCP_PWM);
I see my LCD connected to PORTB becomes crazy. I think there is something wrong with RB3/CCP2. I already assigned CCP2 to RC1 usign CONFIG3 register but I see some strange signal (low freq. pulses) on RB3 which is connected to LCD_RS... If I turn off the PWM, it becomes normal....
any idea about what is wrong?
regards
sobak |
|
|
Ttelmah Guest
|
Re: PWM problem |
Posted: Thu Nov 04, 2004 7:46 am |
|
|
sobak wrote: | I'm trying to produce %50 duty cycle pwm output from RC1/CCP2 on PIC18F8720 and I can do it, I can see with oscilloscope.
but,
when I do that
setup_ccp2(CCP_PWM);
I see my LCD connected to PORTB becomes crazy. I think there is something wrong with RB3/CCP2. I already assigned CCP2 to RC1 usign CONFIG3 register but I see some strange signal (low freq. pulses) on RB3 which is connected to LCD_RS... If I turn off the PWM, it becomes normal....
any idea about what is wrong?
regards
sobak |
You say you have configured CCP2 to RC1 using the config3 register. Now if this is in the programmer, are you doing it after you load the file to program?. The CCS code, _contains_ the config fuses, and these may be overriding the one you are setting. The CCP2 configuration is controlled by the CCP2C1 setting in the #fuses line. I'd try adding this fuse setting, and then seeing if it works.
If not, and this is how you are setting the fus, then are you sure that your programmer is reading them all from the incoming file?.
Best Wishes |
|
|
|
|
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
|