|
|
View previous topic :: View next topic |
Author |
Message |
Andrew Welch Guest
|
PWM Question |
Posted: Mon Feb 10, 2003 12:09 am |
|
|
I want to use CCP1 in PWM mode to generate a 38khz pulse on an IR emitter. I'm using a 20mhz 16F877.
Is this possible? If so, what is the set up code? I'm having a hard time figuring that out.
Thanks...
___________________________
This message was ported from CCS's old forum
Original Post ID: 11465 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
Re: PWM Question |
Posted: Mon Feb 10, 2003 1:15 pm |
|
|
:=I want to use CCP1 in PWM mode to generate a 38khz pulse on an IR emitter. I'm using a 20mhz 16F877.
:=
:=Is this possible? If so, what is the set up code? I'm having a hard time figuring that out.
----------------------------------------------------
Try this:
#include "c:\program files\picc\devices\16F877.h"
#fuses HS,NOWDT,NOPROTECT,PUT,BROWNOUT, NOLVP
#use Delay(clock=20000000)
// #use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
//===============================================
main()
{
output_low(PIN_C1);
setup_ccp1(CCP_PWM); // Configure CCP1 as a PWM
while(1)
{
setup_timer_2(T2_DIV_BY_1, 130, 1); // 38 KHz
set_pwm1_duty(65); // 50\% duty cycle
while(1);
}
___________________________
This message was ported from CCS's old forum
Original Post ID: 11482 |
|
|
Neutone
Joined: 08 Sep 2003 Posts: 839 Location: Houston
|
Re: PWM Question |
Posted: Mon Feb 10, 2003 2:42 pm |
|
|
:=:=I want to use CCP1 in PWM mode to generate a 38khz pulse on an IR emitter. I'm using a 20mhz 16F877.
:=:=
:=:=Is this possible? If so, what is the set up code? I'm having a hard time figuring that out.
:=----------------------------------------------------
:=
:=Try this:
:=
:=#include "c:\program files\picc\devices\16F877.h"
:=#fuses HS,NOWDT,NOPROTECT,PUT,BROWNOUT, NOLVP
:=#use Delay(clock=20000000)
:=// #use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
:=
:=//===============================================
:=main()
:={
:=
:=output_low(PIN_C1);
:=
:=setup_ccp1(CCP_PWM); // Configure CCP1 as a PWM
:=
:=while(1)
:={
:=setup_timer_2(T2_DIV_BY_1, 130, 1); // 38 KHz
:=set_pwm1_duty(65); // 50\% duty cycle
:=
:=while(1);
:=}
Do you want to use a PWM frequency that is 16 times the bit time? The part I use does.
<a href="http://www-s.ti.com/sc/ds/tir1000.pdf" TARGET="_blank">http://www-s.ti.com/sc/ds/tir1000.pdf</a>
bit time 1/(9600)
PWM would be 1/(9600*16)
or 153.6 KHz
bit time 1/(2400)
PWM would be 1/(2400*16)
or 38.4 KHz
It would also help to use a crystal that makes your baud rate and iRDA clocl without errors.
#define XTAL_FREQUENCY 19660800
#use delay(clock=XTAL_FREQUENCY)
___________________________
This message was ported from CCS's old forum
Original Post ID: 11485 |
|
|
Andrew Welch Guest
|
Re: PWM Question |
Posted: Mon Feb 10, 2003 9:32 pm |
|
|
:=:=I want to use CCP1 in PWM mode to generate a 38khz pulse on an IR emitter. I'm using a 20mhz 16F877.
:=:=
:=:=Is this possible? If so, what is the set up code? I'm having a hard time figuring that out.
:=----------------------------------------------------
:=
:=Try this:
:=
:=#include "c:\program files\picc\devices\16F877.h"
:=#fuses HS,NOWDT,NOPROTECT,PUT,BROWNOUT, NOLVP
:=#use Delay(clock=20000000)
:=// #use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
:=
:=//===============================================
:=main()
:={
:=
:=output_low(PIN_C1);
:=
:=setup_ccp1(CCP_PWM); // Configure CCP1 as a PWM
:=
:=while(1)
:={
:=setup_timer_2(T2_DIV_BY_1, 130, 1); // 38 KHz
:=set_pwm1_duty(65); // 50\% duty cycle
:=
:=while(1);
:=}
Thanks very much! I'll give it a try. I wasn't sure of the right parameters for setup_timer.
___________________________
This message was ported from CCS's old forum
Original Post ID: 11504 |
|
|
|
|
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
|