Hello.
I have this simple code - it generates pulses of 300, 600, 1200 and 2400 Hz on PORTC Outputs at same time.
I noticed that there's an output jitter, and it is directly related to the GOTO statement - on each iteration, it takes different time to code to start again, so there is a noticeable jitter.Code:;----[16F886 Hardware Configuration]-------------------------------------------- #CONFIG cfg1 = _INTRC_OSC_NOCLKOUT ; INTOSCIO oscillator: I/O function on RA6/OSC2/CLKOUT pin, I/O function on RA7/OSC1/CLKIN cfg1&= _WDT_ON ; WDT enabled cfg1&= _PWRTE_OFF ; PWRT disabled cfg1&= _MCLRE_OFF ; RE3/MCLR pin function is digital input, MCLR internally tied to VDD cfg1&= _CP_OFF ; Program memory code protection is disabled cfg1&= _CPD_OFF ; Data memory code protection is disabled cfg1&= _BOR_OFF ; BOR disabled cfg1&= _IESO_ON ; Internal/External Switchover mode is enabled cfg1&= _FCMEN_ON ; Fail-Safe Clock Monitor is enabled cfg1&= _LVP_OFF ; RB3 pin has digital I/O, HV on MCLR must be used for programming cfg1&= _DEBUG_OFF ; In-Circuit Debugger disabled, RB6/ICSPCLK and RB7/ICSPDAT are general purpose I/O pins __CONFIG _CONFIG1, cfg1 cfg2 = _BOR40V ; Brown-out Reset set to 4.0V cfg2&= _WRT_OFF ; Write protection off __CONFIG _CONFIG2, cfg2 #ENDCONFIG 'chip configs TRISA=%00000000 'SET A TO OUTPUT 0=INPUT 1 OUTPUT TRISC=0 'set TRISB=0 'set ANSELH=%00000000 ' ADC OFF B ANSEL=%000000000 'configure PortA as digital ADCON1=%10000000 'adc justify OSCCON=%01110101 'SET FREQUENCY TO 8MHZ WPUB=%00000000 'turn off Pullups CM1CON0=0 'DISABLE COMPARATORS CM2CON0=0 'SAME HERE 'CCP1CON=%01000000 ' configure pwm 'PSTRCON=%00010110 'disable C pwm <--- all above enables HPWM on PORTB.4 DEFINE OSC 8 'set oscillator speed 'adcin config DEFINE ADC_BITS 10 DEFINE ADC_CLOCK 3 DEFINE ADC_SAMPLEUS 50 A VAR PORTC.4 B VAR PORTC.5 C VAR PORTC.6 D VAR PORTC.7 x var byte x=0 masfrk: for x=0 to 15 a=x.0 b=x.1 c=x.2 d=x.3 pauseus 194 next goto masfrk
If I change X maximum value from 15 to 255, jitter is significantly reduced, because most time code operates inside for-next loop, which des not has this problem.
Here is a small video showing it - first half of the video the X changes from 0 to 255, and after that I upload another code, where X changes from 0 to 15, and jitter can be clearly seen.
Currently I'm running 16F886 @ 8mhz internal oscillator. If that would be intosc issue, then it should affect the for-next loop too, right? but why it only happens on GOTO, any ways to fix this?




Bookmarks