Ok, a wet VAc has sorted most of my carpet problems, but going straight to the manual for info about using DIV32 has seemingly brought more jitter to the fore....
First here's what I'm doing....
Code:
@ __CONFIG _FCMEN_OFF & _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_OFF & _CP_OFF & _IESO_OFF & _BOR_OFF & _PWRTE_OFF
'***********************************************************************************************
'16F690 Pin Connections....
' PIN# NAME USE & CONNECTION
' 1 Vdd +5VDC power supply
' 7 RC3 C12IN3- (external comparator input)
' 20 Vss Ground
'*************************************************************************************
DEFINE OSC 4 ' set Oscillator at 4Mhz.
DEFINE NO_CLRWDT 1 ' PBP doesn't clear WDT automatically
DEFINE HSER_SPBRG 25 'HSEROUT Stuff.
DEFINE HSER_TXSTA 24h 'HSEROUT Stuff.
DEFINE HSER_CLROERR 1 'HSEROUT Stuff.
txsta = %10100100 'setup the tx register
RCSTA.7 = 1 ' Enable RB7 for TX USART
INTCON.0 = 0 ' clears the RABIF Flag (to 0), COULD be 1 on reset (unique to F690)
ANSEL = 0 'disable AtoD.
ANSELH = 0 'disable AtoD.
CM2CON0 = 0 'turn off comparator 2.
'Turn on & Set up Comparator 1
CM1CON0 = %11100011 'Comparator ext op pin disabled (op of comparator avaible internally only), compare against external VREF
VRCON = %0100001 'turn on internal reference
TRISA.2 = 0 'allow the comparator 1 output pin as an output
MyTime var word ' used to amalgamate TMR1 High & Low Bytes.
Frequency var word 'used to convert the count to frequency.
' the following is pretty much a straight lift from the compiler manual (DIV32 section)
a Var Word
b Var Word
c Var Word
dummy Var Word
b = 500
c = 1000
INCLUDE "DT_INTS-14.bas" ' Base Interrupt System
INCLUDE "ReEnterPBP.bas" ' Include if using PBP interrupts
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler CMP1_INT, _Comp1_Int, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM
T1CON = $11 ; Prescaler setting 2us between clocks
@ INT_ENABLE CMP1_INT ; enable Comparator 1 interrupts
T1CON.0=0 'stop the timer
TMR1H = 0 'Set the high part of the timer value to 0
TMR1L = 0 'Set the low part of the timer value to 0
MyTime = 0 'clear down Mttime, prior to starting.
'Main body of Code*********************************************************************************************
Main:
pause 10
goto Main
end
'Comparator1 Interrupt Handler+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comp1_Int:
if T1CON.0= 0 then 'if timer1 is not running...
TMR1H = 0 'Set the high part of the timer value to 0
TMR1L = 0 'Set the low part of the timer value to 0
T1CON.0= 1 'start timer
else 'therefore if it is running, stop the timer & calculate the number of 'clock' counts between comparator interrupts....
T1CON.0= 0 'stop the timer
MyTime.Lowbyte = TMR1L 'puts the timer's low byte in MyTime's lower 8 bits
MyTime.Highbyte = TMR1H 'puts the timer's high byte in MyTime's upper 8 bits
dummy = b * c ' 'a straight lift from the compiler manual (DIV32 section)
a = DIV32 MYTIME 'use the DIV32 to divide 50,000,000 by the comparator 'time between counts'
hserout ["Comparator1_Count = ", dec MyTime, 9, "Frequency = ", dec a,13, 10]
endif
@ INT_RETURN
....& here's the onscreen hserout data....
(just to remind you 'Comparator1_Count' is the 'number of clocks' counted between successive comparator interrupts - and the frequency is the DIV32 result of 500000 divided by comparator1_count number )
Comparator1_Count = 1960 Frequency = 255
Comparator1_Count = 1961 Frequency = 254
Comparator1_Count = 1960 Frequency = 255
Comparator1_Count = 1960 Frequency = 255
Comparator1_Count = 1961 Frequency = 254
Comparator1_Count = 1960 Frequency = 255
Comparator1_Count = 1960 Frequency = 255
Comparator1_Count = 1961 Frequency = 254
Comparator1_Count = 1959 Frequency = 255
Comparator1_Count = 1960 Frequency = 255
Comparator1_Count = 1961 Frequency = 254
Comparator1_Count = 1959 Frequency = 255
Comparator1_Count = 1961 Frequency = 254
Comparator1_Count = 1960 Frequency = 255
Comparator1_Count = 1960 Frequency = 255
Comparator1_Count = 1961 Frequency = 254
Comparator1_Count = 1960 Frequency = 255
Comparator1_Count = 1960 Frequency = 255
(FWIW My sig gen was showing 255.2Hz on its LED display & using a calculator to divide 500000 by the 'average' comparator1_count of say 1960, works out at 255.1Hz)
so as a percentage the 'variance/jitter' on the lefthand figure (Comparator1_Count) is miniscule....but using the DIV32 seems crank up the 'error' when converted to Hertz? (eg 254, 255, 255, 254)
What am I doing wrong?!
Bookmarks