Ok, so I'm back to PICs after an enforced time away...I'm wanting to get stuck into DDS, but straight out the blocks, I'm confused (it doesn't take much!)
Right, I want a steady and accurate 20khz interrupt rate - being of the lazy ilk, my first port of call was mister_e's mutlicalc ('Timer helper' tab V1.3.1 dated 2006 - is this the latest version?)
I'm using timer2 (8 bit timer)
Oscillator is running @ 16Mhz
The calculator said I should use a preloader of 63
So I knocked up this little program...
Code:@ __CONFIG _CONFIG1, _FCMEN_OFF & _FOSC_INTOSC & _WDTE_OFF & _MCLRE_OFF & _CP_OFF & _IESO_OFF & _BOREN_OFF & _PWRTE_OFF & _LVP_OFF @ __CONFIG _CONFIG2, _LVP_OFF INCLUDE "DT_INTS-14.bas" ' Base Interrupt System Osccon = %01111010 'sets the internal oscillator to 16Mhz DEFINE OSC 16 TrisA.5 = 0 'Pin2 an output. CM1CON0 = 0 ' COMPARATORS OFF CM2CON0 = 0 ' COMPARATORS OFF ASM INT_LIST macro ; IntSource, Label, Type, ResetFlag? INT_Handler TMR2_INT, _DDS, asm, YES endm INT_CREATE ; Creates the interrupt processor ENDASM T2CON.2 = 1 ' Timer2 on PR2 = 63 ' this should yield an interrupt rate of 20khz at 16Mhz. @ INT_ENABLE TMR2_INT Main: pause 100 goto main END '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ DDS: toggle PORTA.5 @ INT_RETURN
But when I actually scope pin 2 - I see a frequency of 31.2Khz - now bearing in mind because I'm toggling, the scoped frequency will be half of the actual interrupt frequency, therefore there must be an interrupt frequency of 62.4khz going on with the PR2 value?!!.
So what am not doing right?!! (it's sure to be embarrasingly simple!)
(oh, btw whats's the purpose of the 'reload (instr cycle)' slider in mister_e's calculator??)
So after dicking about for a while, I decided that better get my backside in gear & knock up a spreadsheet to work this all out...
Now when I scope pin2, I see something more like the expected result - 9.93khz ....but where did the other .07khz go?!!Code:Oscillator Freq 16000000Hz Instruction clock 4000000Hz Time per instru 0.00000025 Seconds PR2 set to 200 counts Interrupt takes 0.00005 Seconds Interrupt Frequency 20000Hz Scoped Toggle rate 10000Hz
So what am I missing to get an accurate interrupt toggle frequency reading of 10khz? (which would be a 20khz interrupt rate)




Bookmarks