View previous topic :: View next topic |
Author |
Message |
Requan
Joined: 11 May 2008 Posts: 74
|
i cant obtain 25% duty PWM |
Posted: Tue Dec 11, 2012 6:11 am |
|
|
Dear All,
I try to obtain 250Hz and 25% PWM, but it didn't work:
Code: |
#include <18F14k22.h>
#fuses XT, NOWDT, PUT,PROTECT,NOPLLEN,BROWNOUT, BORV30, NOLVP
#use delay(clock=4M)
#define LedOK Pin_C2
void main()
{
setup_ccp1(CCP_PWM);
setup_timer_2(T2_DIV_BY_16, 249, 1); //250Hz
set_pwm1_duty(250); //25%
set_tris_c(0x00);
while(TRUE)
{
output_high(LEDOK);
delay_ms(500);
output_low(LEDOK);
delay_ms(800);
}
}
|
It started works from 26%:
Code: |
set_pwm1_duty(260);
|
Could You tell me why?
Best Regards,
Martin |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Tue Dec 11, 2012 8:35 am |
|
|
1024/4=??? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19505
|
|
Posted: Tue Dec 11, 2012 8:37 am |
|
|
1) Search the forum. In particular start with:
<http://www.ccsinfo.com/forum/viewtopic.php?t=45968&start=1>
2) Read the manual entry. What does the line:
"An 8-bit value may be used if the most significant bits are not required. " imply?.
3) What is the difference between 250, and 250L in C?.
Best Wishes |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Tue Dec 11, 2012 3:07 pm |
|
|
This is not very helpful Quote: | I try to obtain 250Hz and 25% PWM, but it didn't work: | I don't wish to sound rude but, I'm not a mind reader.
Tell me:-
1) What you actually got.
2) What is wrong with what you got.
Mike |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Dec 11, 2012 4:13 pm |
|
|
Here is sample code for PWM running at 244 Hz. The duty cycle can
be changed from 0 to 100%. This is done by changing the duty cycle
value in the set_pwm1_duty() function from 0 to 255, by turning a trimpot:
http://www.ccsinfo.com/forum/viewtopic.php?t=40007&start=1
This example uses 8-bit pwm mode. |
|
|
Requan
Joined: 11 May 2008 Posts: 74
|
|
Posted: Wed Dec 12, 2012 1:21 pm |
|
|
All clear, thanks and sorry. |
|
|
|