|
|
View previous topic :: View next topic |
Author |
Message |
Will Reeve
Joined: 30 Oct 2003 Posts: 209 Location: Norfolk, England
|
PWM duty setting with 8bit number |
Posted: Mon Sep 07, 2009 6:59 am |
|
|
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
|
|
Posted: Mon Sep 07, 2009 7:27 am |
|
|
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
|
|
Posted: Mon Sep 07, 2009 7:55 am |
|
|
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. |
|
|
|
|
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
|