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 CCS Technical Support

I can't get more than 256 steps on PWM

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



Joined: 07 Jan 2006
Posts: 64
Location: Braga

View user's profile Send private message Send e-mail MSN Messenger

I can't get more than 256 steps on PWM
PostPosted: Sat Nov 18, 2006 11:15 am     Reply with quote

I'm using a 16F73 and i can't get more than 256 steps on duty cicle,
i made this manual counter to "see" where can duty cicle can go and when i get 1 the duty is a 1% and when i get 255 the duty is at 99%. I need a resolution 1024 , can anybody help me to solve this ?

MY CODE :

void main() {

int_count=INTS_PER_SECOND;
set_timer0(0);

setup_ccp1(CCP_PWM);
setup_ccp2(CCP_PWM);

setup_counters( RTCC_INTERNAL, RTCC_DIV_256 | RTCC_8_BIT);
setup_adc_ports(AN0_AN1_AN3);
setup_adc(ADC_CLOCK_INTERNAL);
enable_interrupts(INT_RTCC);
enable_interrupts(GLOBAL);

setup_timer_2(T2_DIV_BY_4,64,1);

lcd_init();
delay_ms(500);

while(1)
{
printf(lcd_putc,"\fCCP1 d.c. %Lu \nCCP2 d.c. %Lu",A,B);

if (input(UP)){(A=A+1);} // Increase duty, 1 step
if (input(DN)){(A=A-1);} // Decrease duty, 1 step
if (input(UP)&&(input(X10))){(A=A+10);} // Increase duty, 10 step
if (input(DN)&&(input(X10))){(A=A-10);} //Decrease duty, 10 step
set_pwm1_duty(A);
set_pwm2_duty(A);

delay_ms(10);
}
}
Ttelmah
Guest







PostPosted: Sat Nov 18, 2006 3:48 pm     Reply with quote

You don't show how 'A' is defined. It needs to be a _long_ integer, or the PWM, will only give 256 steps.
On top of this, you will need to have timer 2 set as:

setup_timer_2(T2_DIV_BY_1,255,1);

The maximum number of PWM 'steps', is the division value in ths (255) plus one, times 4. To give nearly the same PWM frequency, I have dropped the prescaler to /1.

Best Wishes
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