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 CCS Technical Support

Use of pwm_set_duty_percent

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



Joined: 07 Feb 2008
Posts: 184

View user's profile Send private message

Use of pwm_set_duty_percent
PostPosted: Tue Nov 11, 2025 12:52 pm     Reply with quote

Using a PIC18F86J60 target with CCS PCWH v5.121. I cant get this PWM method to work. Output always 0. Any help is appreciated

Code:

#include <18F86J60.h>
#device ADC=10

#FUSES NOWDT                    //No Watch Dog Timer


#use delay(crystal=25000000)
#use PWM(FREQUENCY=31.25kHz, OUTPUT=PIN_C2, stream = PWM1)
#use PWM(FREQUENCY=31.25kHz, OUTPUT=PIN_C1, stream = PWM2)


void main()                                       
{


 
 pwm_set_duty_percent(PWM1, 500);
 pwm_on(PWM1);
 pwm_set_duty_percent(PWM2, 500);
 pwm_on(PWM2);


while(1)
   {


   
   }
}
gaugeguy



Joined: 05 Apr 2011
Posts: 351

View user's profile Send private message

PostPosted: Tue Nov 11, 2025 2:18 pm     Reply with quote

Add some code in your while(1) loop to toggle another pin manually at 1Hz to make sure your processor is running.
JerryR



Joined: 07 Feb 2008
Posts: 184

View user's profile Send private message

PostPosted: Tue Nov 11, 2025 3:54 pm     Reply with quote

Processor is running fine. Thanks. C1 and C2 toggle.

Thanks
Ttelmah



Joined: 11 Mar 2010
Posts: 19982

View user's profile Send private message

PostPosted: Tue Nov 11, 2025 11:01 pm     Reply with quote

These are PPS outputs.
Now how good the 'smart' functions are at using PPS, varies with compiler
versions. I would be explicit, manually setup the PPS pins for the PWM
modules you want to use, and then use the module name, and not the
pin numbers in the #USE PWM statements.
This is more reliable even on the latest compilers, but on yours I'd say
you have to do this.
JerryR



Joined: 07 Feb 2008
Posts: 184

View user's profile Send private message

PostPosted: Wed Nov 12, 2025 9:08 am     Reply with quote

Ttelmah- Thanks as usual for your kind consideration. I might consider another method to generate reliable PWM from this processor.

I'll keep the group informed
Ttelmah



Joined: 11 Mar 2010
Posts: 19982

View user's profile Send private message

PostPosted: Thu Nov 13, 2025 3:37 am     Reply with quote

Try one simple thing.
Specify the PWM module to use for each.
You are not specifying a module to use. The compiler therefore will by
default use a software PWM. This has very limited abilities compared to
the hardware.
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