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 low frequencies not working

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








PWM low frequencies not working
PostPosted: Sat Aug 22, 2009 11:12 am     Reply with quote

Hello, Hoping someone can tell that I am doing some stupid here. I can not figure out why i can't get a 20 hz PWM to work. I am using the following code and compiler 4.083.

I am using the following calaulation for the PR2:
//16*16*(193+1)*4/4e6 = period = .049 (s)
//f = 20.4 hz

The code is not giving a 20 hz output. Any ideas on what I'm doing wrong?




Code:

#include <18F4520.h>
#fuses INTRC,NOPROTECT,MCLR,NOBROWNOUT,BORV45,NOWDT,WDT128,NOPUT,NOSTVREN,NODEBUG
#fuses NOLVP,NOWRT,NOCPB,NOWRTB,NOWRTC,NOCPD,NOWRTD,NOEBTR,NOEBTRB
#fuses NOXINST    //extended cpu
#fuses CCP2B3  //multiplex ccp2 to rb3
#use delay(clock=4000000)


#include <lcd_picdem2_2.c>

//ccp2 to rb3 ccp2mx : multiplex ccp2 to rb3: use fuse

//*********************************************************************
void main(){
int8 i = 0, j = 0;

lcd_init();
set_tris_b(0x00);
set_tris_c(0x00);


//tested
/*
setup_ccp1(CCP_PWM);
setup_ccp2(CCP_PWM);
setup_timer_2(T2_DIV_BY_1,32,1);//32.25 khz to get 7 bits resolution for duty cycle//see equeation
*/


setup_ccp1(CCP_PWM);
//16*16*(193+1)*4/4e6 = period = .049
//f = 20.4 hz
setup_timer_2(T2_DIV_BY_16,194, 16);

while(1){



}//while
}//main
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Aug 22, 2009 11:31 am     Reply with quote

The PWM frequency formula is in this thread and in the PIC data sheet:
http://www.ccsinfo.com/forum/viewtopic.php?t=17993

If you still have a problem, then tell us your overall purpose and why
you need a PWM frequency of 20 Hz.
Guest








PostPosted: Sat Aug 22, 2009 5:35 pm     Reply with quote

Ahhhh, postscaler confusion.

The purpose is just for fun stuff. Blinking some led arrays (visibly). Wanted to have some routines that required minimal software control. I see Ttelmah and you have pointed out some good methods in the linked posts. I will implement some of them.

Thanks for the amazing support, as always.
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