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

Help on PWM generation

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



Joined: 28 Apr 2004
Posts: 2

View user's profile Send private message

Help on PWM generation
PostPosted: Wed Apr 28, 2004 2:15 am     Reply with quote

Hi

I am using PIC 16F819 in my design to generate the PWM Waveform
To start with I have used the code from the example program

setup_ccp1(CCP_PWM); // Configure CCP1 as a PWM
setup_timer_2(T2_DIV_BY_16, 127, 1);
set_pwm1_duty(value);

There was no compilation error , But after programming the target , I could not see any waveform at the CCP1 Output
When I run the debugger , & view the registers , CCP1Con is having the POR value ( ooh)

Am I doing anything wrong ?
Any relevant info would be highly appreciated

Thanks in advance
Best regards,
Haplo



Joined: 06 Sep 2003
Posts: 659
Location: Sydney, Australia

View user's profile Send private message

PostPosted: Wed Apr 28, 2004 2:39 am     Reply with quote

Have you changed the direction of CCP1 pin to output? It is set to input by default at startup.
Guest








PostPosted: Wed Apr 28, 2004 2:50 am     Reply with quote

Haplo wrote:
Have you changed the direction of CCP1 pin to output? It is set to input by default at startup.


Hi Ali,

Thanks for the reply
I understand this is done by setup_ccp1(CCP_PWM);
Btw,Is there any other function available for setting the direction of CCP1 ?

Thanks again,
Best regards,
Raghu
Haplo



Joined: 06 Sep 2003
Posts: 659
Location: Sydney, Australia

View user's profile Send private message

PostPosted: Wed Apr 28, 2004 3:01 am     Reply with quote

On PIC16F819, CCP1 is RB2. setup_ccp1(CCP_PWM) is not enough, you have to set TRISB properly to make that pin an output. Here is a code that does it for you:

set_tris_b(0b11111011);

The above line sets all the PORTB pins to inputs except for RB2 which is set to output. Each pin on PORTB has a corresponding direction bit in the TRISB register. Setting a direction bit to 1 makes that pin input, and setting it to zero makes it output. So as you see in the above code all the direction bits for PORTB are set to 1 (input) except bit 2 which is set to zero (output). You may need to also change the direction of the other pins based on your application.
Refer to the device datasheet and CCS manual for more information.
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