| View previous topic :: View next topic |
| Author |
Message |
JerryR
Joined: 07 Feb 2008 Posts: 184
|
| Use of pwm_set_duty_percent |
Posted: Tue Nov 11, 2025 12:52 pm |
|
|
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
|
|
Posted: Tue Nov 11, 2025 2:18 pm |
|
|
| 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
|
|
Posted: Tue Nov 11, 2025 3:54 pm |
|
|
Processor is running fine. Thanks. C1 and C2 toggle.
Thanks |
|
 |
Ttelmah
Joined: 11 Mar 2010 Posts: 19982
|
|
Posted: Tue Nov 11, 2025 11:01 pm |
|
|
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
|
|
Posted: Wed Nov 12, 2025 9:08 am |
|
|
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
|
|
Posted: Thu Nov 13, 2025 3:37 am |
|
|
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. |
|
 |
|