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

i cant obtain 25% duty PWM

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



Joined: 11 May 2008
Posts: 74

View user's profile Send private message

i cant obtain 25% duty PWM
PostPosted: Tue Dec 11, 2012 6:11 am     Reply with quote

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

View user's profile Send private message AIM Address

PostPosted: Tue Dec 11, 2012 8:35 am     Reply with quote

1024/4=???
Ttelmah



Joined: 11 Mar 2010
Posts: 19338

View user's profile Send private message

PostPosted: Tue Dec 11, 2012 8:37 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Dec 11, 2012 3:07 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Dec 11, 2012 4:13 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Dec 12, 2012 1:21 pm     Reply with quote

All clear, thanks and sorry.
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