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

Need help with PWM on 16F15323
Goto page Previous  1, 2
 
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: 48

View user's profile Send private message

PostPosted: Wed Sep 19, 2018 12:31 pm     Reply with quote

Sorry, not able to measure it. If I use the #use pwm directive, the waveform is cleaner at lower frequencies (~10 kHz).
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Wed Sep 19, 2018 12:38 pm     Reply with quote

Also, are you saying that you set the PWM to a fixed value, and it then shows jitter?. Or are you changing the duty cycle?.
randy.shaffer



Joined: 21 Mar 2018
Posts: 48

View user's profile Send private message

PostPosted: Wed Sep 19, 2018 12:39 pm     Reply with quote

The duty ratio and frequency are both fixed. The latest posted code produces the jittery waveform.
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Wed Sep 19, 2018 12:46 pm     Reply with quote

Can you add the fuse NOWDT to your code.

Fuses default to their erased state. The default for the WDT will be enabled.
With the WDT enabled, and not being reset, the code will reset, and the PWM will show jitter. This will get worse as the frequency goes up.
randy.shaffer



Joined: 21 Mar 2018
Posts: 48

View user's profile Send private message

PostPosted: Wed Sep 19, 2018 12:51 pm     Reply with quote

Code:
#include <16F15323.h>
#fuses NOWDT
#PIN_SELECT CCP1OUT = PIN_A2
void main()
{
 setup_oscillator(OSC_HFINTRC_32MHZ);
 Setup_CCP1(CCP_PWM);
 setup_timer_2(T2_DIV_BY_1 | T2_CLK_INTERNAL, 79, 1);
 set_tris_a(0xFB); // set A2 as output
 set_PWM1_duty(160);
 while(TRUE)
 {
  // ...
 }
}


I added the fuse but the jitter remains the same. I do appreciate the help, however.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Sep 19, 2018 12:54 pm     Reply with quote

Are you testing the jitter with that short little program ? Or, is your posted
code just a small excerpt from a larger program ?

Because in your earlier posted code on page 1, you enable Timer0
interrupts but you don't show an interrupt routine.
randy.shaffer



Joined: 21 Mar 2018
Posts: 48

View user's profile Send private message

PostPosted: Wed Sep 19, 2018 12:58 pm     Reply with quote

Yes, testing with the short program just posted. I created the short program in an attempt to debug this jitter problem. Thank you for the response.
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Wed Sep 19, 2018 1:13 pm     Reply with quote

Set the timer2 clock to be from Fosc/4, and synchronous.

setup_timer_2(T2_DIV_BY_1 | T2_CLK_INTERNAL | T2_SYNC_ON_WITH_T2CLK , 99, 1);

It's possible that the sync, which will change where the clock actually 'is' relative to Fosc, may help.
randy.shaffer



Joined: 21 Mar 2018
Posts: 48

View user's profile Send private message

PostPosted: Wed Sep 19, 2018 1:50 pm     Reply with quote

Code:
#include <16F15323.h>
#fuses NOWDT
#PIN_SELECT CCP1OUT = PIN_A2
void main()
{
 setup_oscillator(OSC_HFINTRC_32MHZ);
 Setup_CCP1(CCP_PWM);
 setup_timer_2(T2_DIV_BY_1 | T2_CLK_INTERNAL | T2_SYNC_ON_WITH_T2CLK, 79, 1);
 set_tris_a(0xFB); // set A2 as output
 set_PWM1_duty(160);
 while(TRUE)
 {
  // ...
 }
}

Still the same jitter. But I am very grateful for the help.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Sep 19, 2018 5:47 pm     Reply with quote

Try using it with a crystal instead of the internal oscillator.
I don't have one of these PICs so I can't test it. It's just a suggeston.
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Thu Sep 20, 2018 1:49 am     Reply with quote

Though not this chip, this might be interesting:

<https://www.microchip.com/forums/m18192.aspx>

Issue with a batch of chips having jitter on the internal clock....

However the commonest cause of variation on the internal RC, is supply ripple. How is the chip supplied?. What smoothing?. etc..
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
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