CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

PWM Question

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Andrew Welch
Guest







PWM Question
PostPosted: Mon Feb 10, 2003 12:09 am     Reply with quote

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

View user's profile Send private message

Re: PWM Question
PostPosted: Mon Feb 10, 2003 1:15 pm     Reply with quote

:=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

View user's profile Send private message

Re: PWM Question
PostPosted: Mon Feb 10, 2003 2:42 pm     Reply with quote

:=:=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
PostPosted: Mon Feb 10, 2003 9:32 pm     Reply with quote

:=:=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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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