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

Low PWM without stress timer

 
Post new topic   Reply to topic    CCS Forum Index -> Code Library
View previous topic :: View next topic  
Author Message
wangine



Joined: 07 Jul 2009
Posts: 98
Location: Curtea de Arges, Romania

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

Low PWM without stress timer
PostPosted: Tue Nov 17, 2015 12:51 pm     Reply with quote

I see here and on internet also many issues trying to get low frequency PWM, of course without stress timer. The function was made trying to get 1Hz PWM with normal duty 0-100.
Code:

//   ~~~~~~~~~~~~~~~~~~~~~once at n ms~~~~~~~~~~~~~~~~~~~~~~   
#define pwm_pin PIN_x // output PWM pin
#define duty_min  1
#define duty_max 100
void timer_pwm(unsigned int8 duty)
{
      if(pwm_period <= duty_min)
         output_high(pwm_pin);
      if(pwm_period == duty)
         output_low(pwm_pin);   
      
      if(pwm_period >=duty_max)
      pwm_period = 0;
}

duty is actual state of PWM between 1-100%
Code:

int8 pwm_period = 0;
#INT_TIMER1
void TIMER1_isr(void)
{
   timer_pwm(open_duty);
   pwm_period++;
}

Each one can set a timer on any low frequency need. Example, at 10ms timer set, 10*pwm_period=1000 => 1Hz frequency PWM with variable duty. The function can update in any other functions. Also can be easy set any duty limits.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> Code Library 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