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

PWM shuts off unexpectedly for 16LF1503

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



Joined: 21 Mar 2018
Posts: 51

View user's profile Send private message

PWM shuts off unexpectedly for 16LF1503
PostPosted: Fri Oct 11, 2024 12:21 pm     Reply with quote

Code:
#include <16LF1503.h> // device file
#fuses NOWDT, NOBROWNOUT
#use delay(internal = 16MHZ)
#use PWM(PWM1, FREQUENCY = 15.625kHz, OUTPUT = PIN_C5, PWM_OFF, STREAM = IN1)
#byte PORTC = 0x00E
#bit IN2 = PORTC.3
void main()
{
 set_tris_c(0b00000100); // X: C7,C6. Inputs: C2. Outputs: C5,C4,C3,C1,C0.
 IN2 = FALSE;
 delay_ms(100); // supply voltage settling time
 pwm_set_duty_percent(IN1, 1000);
 pwm_on(IN1);
 delay_ms(1000); // 100% duty for 1 second
 pwm_set_duty_percent(IN1, 500); // after 1 second, reduce duty to 50%
 pwm_on(IN1);
 while(TRUE);
}


Compiler is v5.118. Program outputs 100% duty initially. After one second, I wanted to drop the duty ratio to 50%, but it drops to zero instead. Thanks for having a look.
Ttelmah



Joined: 11 Mar 2010
Posts: 19511

View user's profile Send private message

PostPosted: Sat Oct 12, 2024 7:48 am     Reply with quote

Cannot see any reason why. Looking at the assembly this generates the
value is sensible.
You don't need to enable the PWM a second time.

I think you need to narrow down whether the chip might be stopping
for some other reason. Leave the 100% running for 5 seconds. Does the
output stay running?.
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