![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Sep 17, 2009 5:08 pm |
|
|
Here's an example of 10-bit PWM mode. If you turn the trimpot, it
changes the PWM duty cycle.
Code: | #include <16F877.h>
#device adc=10
#fuses XT,NOWDT,NOPROTECT,BROWNOUT,PUT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
//================================
void main()
{
int16 value;
setup_ccp1(CCP_PWM);
// Set the PWM frequency for 245 Hz (with a 4 MHz crystal)
setup_timer_2(T2_DIV_BY_16, 254, 1);
setup_port_a(AN0);
setup_adc(ADC_CLOCK_DIV_8); // Divisor for 4 MHz crystal
set_adc_channel(0);
delay_us(20);
while(1)
{
value = read_adc(); // 10-bit ADC result
set_pwm1_duty(value);
}
} |
|
|
![](templates/subSilver/images/spacer.gif) |
ccowley
Joined: 12 Sep 2009 Posts: 19
|
Thanks for trying to help! |
Posted: Thu Sep 17, 2009 8:36 pm |
|
|
I appreciate the effort at helping me out! As I mentioned, I have read everything I could find on it already, so I have already looked at that code. I guess what I am really asking is, "What is wrong with my code, that it doesn't work?" I must be doing something wrong, but I am not sure what it is. I am still in the process of getting a grip on the C language.
Do you see anything wrong my code? I will continue to tinker around and try to solve the problem. I just thought someone might be able to quickly see what my coding problem was so that I wouldn't have to continue spending so much time with the trial and error route.
Thanks again, I do appreciate the effort! |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Sep 17, 2009 8:43 pm |
|
|
Most of the code in your program is unnecessary for PWM.
Look closely at the functions in my program, and compare the parameters
that I use to the ones that you use in the same functions. You will see
the problem. |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|