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

How to use #use pwm()

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



Joined: 26 Sep 2020
Posts: 51

View user's profile Send private message

How to use #use pwm()
PostPosted: Thu Jun 24, 2021 1:32 am     Reply with quote

How to use #use pwm() on devices with multiple independent PWMs ?
For example: is it possible to apply this directive for separate control of PWM1, PWM2, PWM3, PWM4 ? And if so, then how exactly to do it for BIF pwm_off() and pwm_on() ?
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Thu Jun 24, 2021 2:15 am     Reply with quote

Using multiple #use pwm statements is shown here:
http://www.ccsinfo.com/forum/viewtopic.php?t=59193&highlight=pwm

Each pwm, needs a specific stream name, and this can then be given
to the off/on functions.
dmitrboristuk



Joined: 26 Sep 2020
Posts: 51

View user's profile Send private message

PostPosted: Thu Jun 24, 2021 3:20 am     Reply with quote

Code:

#use delay ( clock = 16000000 )
#USE PWM(CCP1, OUTPUT=PIN_C1, TIMER=2, FREQUENCY=10kHz, DUTY=50, PWM_OFF, STREAM=1)
#USE PWM(PWM3, OUTPUT=PIN_C2, TIMER=4, FREQUENCY=5kHz, DUTY=25, PWM_OFF, STREAM=2)
#USE PWM(PWM4, OUTPUT=PIN_C3, TIMER=6, FREQUENCY=3.33kHz, DUTY=16.6, PWM_OFF, STREAM=3)

// for example

void main(void)     
{

   pwm_on (1);
   pwm_on (2);
   pwm_off (3);
   delay_ms (20);
   pwm_off (1);
   pwm_off (2);
   pwm_on (3);

   while(TRUE)
   {}           
}


is it right?
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Thu Jun 24, 2021 3:55 am     Reply with quote

Stream names, need to be unique names, not just numbers.
Without knowing what chip you are using, can't know if it supports
the pins and timers you are specifying.
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