View previous topic :: View next topic |
Author |
Message |
randy.shaffer
Joined: 21 Mar 2018 Posts: 51
|
|
Posted: Wed Sep 19, 2018 12:31 pm |
|
|
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: 19466
|
|
Posted: Wed Sep 19, 2018 12:38 pm |
|
|
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: 51
|
|
Posted: Wed Sep 19, 2018 12:39 pm |
|
|
The duty ratio and frequency are both fixed. The latest posted code produces the jittery waveform. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19466
|
|
Posted: Wed Sep 19, 2018 12:46 pm |
|
|
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: 51
|
|
Posted: Wed Sep 19, 2018 12:51 pm |
|
|
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
|
|
Posted: Wed Sep 19, 2018 12:54 pm |
|
|
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: 51
|
|
Posted: Wed Sep 19, 2018 12:58 pm |
|
|
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: 19466
|
|
Posted: Wed Sep 19, 2018 1:13 pm |
|
|
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: 51
|
|
Posted: Wed Sep 19, 2018 1:50 pm |
|
|
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
|
|
Posted: Wed Sep 19, 2018 5:47 pm |
|
|
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: 19466
|
|
Posted: Thu Sep 20, 2018 1:49 am |
|
|
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.. |
|
|
|