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

Anyone have PWM working with PIC16LF15325?

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



Joined: 01 Apr 2007
Posts: 203

View user's profile Send private message

Anyone have PWM working with PIC16LF15325?
PostPosted: Mon Apr 07, 2025 6:40 pm     Reply with quote

Has anyone gotten the PWM to work with the PIC16LF15325?

If so, would you post a very simple code example of the setup? Any frequency, duty cycle, or output pin.

I have tried all traditional methods of getting this to work and they all fail with an output of 0.

Thanks.
randy.shaffer



Joined: 21 Mar 2018
Posts: 63

View user's profile Send private message

PostPosted: Thu Apr 17, 2025 2:24 pm     Reply with quote

I don't have that chip to try this code on, but this is the approach that I would take:

Code:

#include <16LF15325.h>
#fuses NOWDT
#use delay(internal = 32MHZ)
#use PWM(FREQUENCY=31.25kHz, OUTPUT=PIN_A5, stream = PWM_OUT)
void main()
{
 set_tris_a(0b00001011);
 pwm_set_duty_percent(PWM_OUT, 500);
 pwm_on(PWM_OUT);
 while(TRUE)
 {
 }
}
starfire151



Joined: 01 Apr 2007
Posts: 203

View user's profile Send private message

PostPosted: Thu Apr 17, 2025 2:57 pm     Reply with quote

THANK YOU!

That worked!

Apparently my original code specified the output pin through a pin select. This did not work. When I specify the output pin through the #use PWM() function, as your code did, it goes to the right pin and works.

...and I didn't even need to specify setup_timer_2().

Interesting...

Thanks, again!
randy.shaffer



Joined: 21 Mar 2018
Posts: 63

View user's profile Send private message

PostPosted: Thu Apr 17, 2025 3:02 pm     Reply with quote

I'm glad to hear that it worked! The timer can be specified in the #use pwm statement, but timer 2 is the default.
Ttelmah



Joined: 11 Mar 2010
Posts: 19779

View user's profile Send private message

PostPosted: Fri Apr 18, 2025 12:14 am     Reply with quote

It is almost certainly using CCP1, not PWM3.
The #use pwm function, seems to have some major problems with handling
ECCP or PWM peripherals, rather than the standard CCP. It works on some
chips, but has problems on others. On the ones with problems, you have
to go 'manual', and use the setup functions, rather than the #use.

I must admit I'd always use the manual setups, not #use. I want to know
from the data sheet what the limitations are on resolution and speed, and
choose the clock rates and setups to optimise my final result. Now (conversely), I'd use #USE RS232 all the time. Where I don't like the
#USE functions, is situations like this where the chip has two distinct
peripherals that can both do the job. I want to know which one is being
used, and the #USE PWM, does not allow this to be properly controlled.
It also has limitations when dealing with different modes for the more
sophisticated peripheral. For example, gating. These extra features require
the setup functions to be used, and the exact behaviour of 'USE is often
poorly documented, so better to actually know what you are doing, than
rely on shortcuts like this.
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