View previous topic :: View next topic |
Author |
Message |
raghu
Joined: 28 Apr 2004 Posts: 2
|
Help on PWM generation |
Posted: Wed Apr 28, 2004 2:15 am |
|
|
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
|
|
Posted: Wed Apr 28, 2004 2:39 am |
|
|
Have you changed the direction of CCP1 pin to output? It is set to input by default at startup. |
|
|
Guest
|
|
Posted: Wed Apr 28, 2004 2:50 am |
|
|
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
|
|
Posted: Wed Apr 28, 2004 3:01 am |
|
|
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. |
|
|
|