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

10 bit hardware PWM on a 12F683

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



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Sep 17, 2009 5:08 pm     Reply with quote

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);
  }


}
ccowley



Joined: 12 Sep 2009
Posts: 19

View user's profile Send private message

Thanks for trying to help!
PostPosted: Thu Sep 17, 2009 8:36 pm     Reply with quote

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!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Sep 17, 2009 8:43 pm     Reply with quote

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.
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