16F18877 - Internal Oscillator Jitter Issues

Thread Starter

TCOP

Joined Apr 27, 2011
94
Hi everyone,
I am using 16F18877 with internal oscillator at 32Mhz (8 mhz clock). I am creating a VGA signal to drive an old lcd monitor (800x600 @40mhz).
Hsync is produced using TMR2 in PWM mode and Vsync is produced using TMR1 is compare mode. Everything works great but I have jitter problems.
I notice 1-2 pixels of random phase shift in everyline. See the effect in attached picture.
I am using a logic analyzer to see the data and I notice that the period of the horizontal pulses is slightly different every few pulses. It ranges from 26.2μs to 26.6μs while I target for 26.375. Now I am not sure how to handle this. Is it something that I can't tweak somehow or is it a normal behavior of the internal oscillator and I can only switch to an external crystal to resolve it?
I have used a 0.1μf decoupling capacitor in each of the two pic VDD pins but this is the first time I used an LM2596 - 5v as a switching power source and I am not sure If this is affects the stability of the clock.
Any ideas will be more than welcome.
 

Attachments

Last edited:

Thread Starter

TCOP

Joined Apr 27, 2011
94
I suspect that this is a coding issue not the oscillator.
It can't be the coding. It is just a pwm signal. Not even an interrupt. I switch it on and leave it this way. I see jitter even when i enable the Clock Out bit and use the logic analyzer to measure the clock pulses. I measure the correct number of pulses per second but there are many pulses with wrong period. Either the negative side is longer or the positive.
 

AlbertHall

Joined Jun 4, 2014
9,835
Is the HSYNC pulse the correct width - if not it may be the monitor sync circuit struggling.
Else connect a linear 5V power supply temporarily and disable the LM2596 to eliminate that possibility.
 

Thread Starter

TCOP

Joined Apr 27, 2011
94
It is a bit hard to desolder but I will give it a try tomorrow. I tried adding some extra decoupling capacitors with no luck. Then I took the largest electrolytic capacitor i had on hand (2200μf @12V) and hold it on +5 and GND of LM2596. The effect on the jitter was obvious and there was a significant improvement. So there is probably some interference with the power supply but I'll have to investigate it a bit more.
Do you think that the internal oscillator is going to work or should I switch to a external crystal?
 
Last edited:

AlbertHall

Joined Jun 4, 2014
9,835
It is a bit hard to desolder but I will give it a try tomorrow. I tried adding some extra decoupling capacitors with no luck. Then I took the largest electrolytic capacitor i had on hand (2200μf @12V) and hold it on +5 and GND of LM2596. The effect on the jitter was obvious and there was a significant improvement. So there is probably some interference with the power supply but I'll have to investigate it a bit more.
Do you think that the internal oscillator is going to work or should I switch to a external crystal?
It may be that ripple on the supply disturbs the oscillator.
 

nsaspook

Joined Aug 27, 2009
7,284
It is a bit hard to desolder but I will give it a try tomorrow. I tried adding some extra decoupling capacitors with no luck. Then I took the largest electrolytic capacitor i had on hand (2200μf @12V) and hold it on +5 and GND of LM2596. The effect on the jitter was obvious and there was a significant improvement. So there is probably some interference with the power supply but I'll have to investigate it a bit more.
Do you think that the internal oscillator is going to work or should I switch to a external crystal?
Don't use the internal rc oscillator for precision timing, ever, never.
http://ww1.microchip.com/downloads/en/devicedoc/31002a.pdf
 
Last edited:

Thread Starter

TCOP

Joined Apr 27, 2011
94
I switched to a linear power supply (7805). There is an obvious improvement but the jitter is still there. Just less intense.
Now the next step is the crystal. Any tips regarding its selection? Should I go for an 8 Mhz and use x 4 PLL setting or search for a 32 Mhz crystal.
 

Thread Starter

TCOP

Joined Apr 27, 2011
94
I just used a 20Mhz crystal cause I had nothing else available. Changed the timings and fired.
Jitter is completly gone! The signal is 100% stable. I almost never use external crystals and I had no idea of it.
I really cannot believe it!
 
Top