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 Problem

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



Joined: 10 Apr 2006
Posts: 22

View user's profile Send private message

PWM Problem
PostPosted: Fri Apr 21, 2006 9:35 am     Reply with quote

Hello again,

i am trying to utilize PWM on a pic16f914. I have read a few threads and it seems like the output frequency is no where near the calculated 1.5khz that i need is on pin C2 pwm output. Pin C2 is configured for me by the compiler, am i supposed to use ccp1 which is Pin C5. I have tried diiferent settings for timer2 and does not go below what seems to be a few mhz.
I can change the duty cycle but freq. remains high.
Thanks!
Code:

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES INTRC_IO                 //Internal RC Osc, no CLKOUT
#FUSES PUT                      //Power Up Timer
#FUSES NOPROTECT                //Code not protected from reading
#FUSES MCLR                     //Master Clear pin enabled
#FUSES NOCPD                    //No EE protection
#FUSES BROWNOUT                 //Reset when brownout detected
#FUSES NOIESO                   //Internal External Switch Over mode disabled
#FUSES NOFCMEN                  //Fail-safe clock monitor disabled
#FUSES NODEBUG                  //No Debug mode for ICD
#use delay(clock=4000000)

void main()
{

   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_OFF);
   setup_spi(FALSE);
   setup_lcd(LCD_DISABLED);
   setup_timer_2(T2_DIV_BY_16,255,16);
   setup_ccp1(CCP_PWM);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   setup_oscillator(OSC_4MHZ);
   
 while (true)
{
output_low(PIN_C2);
set_pwm1_duty(500);
output_high(PIN_C2);
}

}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Apr 21, 2006 12:43 pm     Reply with quote

Quote:

I am trying to utilize PWM on a pic16f914. I have read a few threads and
it seems like the output frequency is no where near the calculated 1.5khz

How did you get the 1.5 KHz ?

If you go to this thread, it has a formula to calculate the PWM frequency:
http://www.ccsinfo.com/forum/viewtopic.php?t=17993

If I take the values from your program and plug them into that formula,
I get this:

Code:
      4 MHz
------------------- = 244 Hz
(255 +1) x 16 x 4


I converted your program to run on my test board, which has a 16F877.
It's a similar chip, so the PWM module runs the same.

I measured a frequency on Pin C2 of 244.15 Hz with my oscilloscope.
That fits the equation.
janiga



Joined: 10 Apr 2006
Posts: 22

View user's profile Send private message

Thanks Again!
PostPosted: Fri Apr 21, 2006 6:00 pm     Reply with quote

I had to switch to pin C5 which on my processor is the ccp1 pin. It works great and am implementing PWM and getting rid of all the while loops that simulated PWM!

Again Thank You!

Pedro Very Happy
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