Ok, after staring at your code for 2 hours (ie until I actually looked like my Avatar!) .....your code slowly morphs into a magic eye puzzle with the words "Hank is a bit slow" popping out in 3D.
I'd like to get to the bottom of how you set the frequency up for DDS related stuff - I think I get the jist.
You are preloading timer1 with a 'preset count' to change the sine wave frequency (in your example FD85 ,which in decimal is 64901)
Therefore Timer 1 is a 32 bit timer, which means it'll overlow at 65535 ...so you have 65535 - 64901 = 351 counts, before the code jumps to the interrupt handler (towards reading the next value in the sine wave array).
Have I got this right?
Ok, my PIC won't run at 40Mhz, so I can't copy your example 'like for like', but I'm getting an odd result - don't get me wrong, I get a decent sine wave, but not at the frequency I was expecting.
Basically, when I type my particular settings into Mister_E's calc & divide his Interrupt frequency result by 32 (this being the amount of interrupts it takes to make one complete sine wave cycle?) ...the result is different to what I'm seeing on myscope!
So...my settings.
20Mhz Oscillator (ceramic resonator)
16 bit timer
1:1 prescaler
Timer1 preloaded with 65122
According to Mr E's calculator that should give an interrupt frequency of 12.048Khz - it should be just a matter of dividing that by 32 to get the sine wave coming out of the filter? (ie it takes 32 interrupts to build a full sine wave)
therefore 12048/32 = 376.5Hz.
But I'm seeing a 348Hz sine wave on my scope??
So I wanted to check the actual interrupt frequency, therefore I added a 'toggle a pin' into your interrupt handler - that resulting square wave output registers @5580Hz ...this needs to be doubled this to get the actual interrupt rate, therefore the interrupt rate appears to be just 11160Hz (which if I divide by 32, surprise surprise is what my scope is seeing as a sine wave - 348.75Hz)
I guess it takes time to service the interrupts & actually do stuff in the routine ...but that equates to about 30 timer1 counts going AWOL ...which seems a lot?
So any idea why the discrepancy between Mister_E's calculator (which is surely right) & what I'm seeing on my scope (my scope is accurate btw!).

Green trace (& text) relates to the sine wave, yellow trace relates to the square wave from the interrupt pin toggling (to trap the actual 'interrupt' frequency externally on my scope)
Code:
timerone var word
INCLUDE "DT_INTS-14.bas" ; Base Interrupt System
;include "ReEnterPBP-18.bas" ;not needed for ASM type interrupt service routines
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler TMR1_INT, _sine, ASM, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM
T1CON.5 = 0
T1CON.4 = 0
TMR1L = 255
TMR1H = 254
@ INT_ENABLE TMR1_INT ; Enable Timer 1 Interrupts
'timerone = $FD85 ;gives about 60 htz sine ;gives about 60 htz sine
timerone = 65122 ;gives about 60 htz sine ;gives about 60 htz sine
Main:
pause 1
GOTO Main
'---[TMR1_INT - interrupt handler]------------------------------------------
sine:
TMR1L = timerone.byte0
TMR1H = timerone.byte1
CCPR1L = sineval[STEPCOUNT]>>1
stepcount = stepcount -1
if stepcount = 0 then stepcount = 32
toggle PortC.4
@ INT_RETURN
Could this be just down to me using a ceramic resonator @20Mhz (I have no idea what spec these things have, but the discrepancy amount to some 10%?)
Bookmarks