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

PWM duty setting with 8bit number

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



Joined: 30 Oct 2003
Posts: 209
Location: Norfolk, England

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

PWM duty setting with 8bit number
PostPosted: Mon Sep 07, 2009 6:59 am     Reply with quote

PWM duty cycle bug? v4.099

Code:
set_pwm2_duty(200);


give a different result to:

Code:
int16 test=200;
set_pwm2_duty(test);


It seems sending 8bits into set_pwm2_duty is broken?
Code:

....................    set_pwm2_duty(200);
009B2:  MOVLW  C8
009B4:  MOVWF  FBB
....................    delay_cycles(1);
009B6:  NOP 


Don't you have to clear the two top bits of the 10bit number?
Ttelmah
Guest







PostPosted: Mon Sep 07, 2009 7:27 am     Reply with quote

It wil do.

It is in the manual.......
It has also been covered here many times.

The set_pwm_duty function, has two different modes of operation, according to whether the value it receives, is an 8bit value, or a 16bit value. If you pass an 8bit value, it only accesses the top 8bits of the 10 bit register, saving the overhead of masking off the two low bits, and putting these into the separate locations. Pass a 16bit value, and the extra work is done. Makes it possible for _you_ to decide if you need to perform a 10bit access, or only the 8bit access.

When using a constant, you need to tell the compiler _explicitly_, that you want it to treat the value as a 16bit number, if you want the 16bit operation, if the value is below 256:

Code:

set_pwm2_duty(200L); //Note the 'L'
//or
set_pwm2_duty((int16)200);


Best Wishes
Will Reeve



Joined: 30 Oct 2003
Posts: 209
Location: Norfolk, England

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

PostPosted: Mon Sep 07, 2009 7:55 am     Reply with quote

Thanks, the "8-bit value may be used if the most significant bits are not required" on first read I though that the "required" referred to me and not the hardware :-)
Thanks for the L thing, you learn something every day. I am now changing my set_pwmx_duty(0) to set_pwmx_duty(0L) to be sure the top two bits are 0.
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