Hi Steve
Sorry I forgot to mention It is in an 18F4520, actually it's on a fairly well modified LABX1 board, Ill migrate to a suitable MCu after I have finished.
and I had a scout about the forum for info about the VB code to do all sorts of wonderfull things to the post
simpleCode:define OSC 16 INCLUDE "DT_INTS-18.bas" ; Base Interrupt System INCLUDE "ReEnterPBP-18.bas" ; Include if using PBP interrupts ASM INT_LIST macro ; IntSource, Label, Type, ResetFlag? INT_Handler CMP_INT, _StartTag, PBP, yes INT_Handler TMR0_INT, _AllDone, PBP, yes endm INT_CREATE ENDASM TRISA = %00001111 TRISB = %11011111 TRISC = %00111111 TRISD = %00000000 PORTD = 0 Z var byte T0CON = %10000011 'set up timer 0 and turn it ON @16mhz 0011 = 262ms CMCON = %00100011 ' set up comparator inputs @ INT_ENABLE TMR0_INT ;all done T0CON.7 = 0 ' turn off timer until needed start: portd.5 = 0 '============================================================= '============================================================= Get_Raw_Data:' GET RAW DATA '-------------------------------------------------- Z = 0----------------- @ INT_ENABLE CMP_INT ;wait here until an interrupt event Z = 0 'on the comparators Waiting: if z = 0 then waiting @ INT_DISABLE CMP_INT '----------------------------------------- Z = 1-------------------- portd.5 = 1 'all done marker TMR0H = %00111100 ' preload timer to 15400 TMR0L = %00100000 T0CON.7 = 1 ' turn back on timer 0 , used by all done getData: ']loop here until timer1 overflows if z = 1 then getdata '] '--------------------------------------------Z = 4----------------- getout: PORTD.5 = 0 'all done marker T0CON.7 = 0 'turn timer0 off until used again finished: goto start ;;;;;;;;;;;;;;;;;;;;; interrupt handlers ;;;;;;;;;;;;;;;;;;;;;; StartTag: z = 1 ' moves towards middle of routine @ INT_RETURN AllDone: z = 4 ' moves towards end of routine @ INT_RETURN end
Loading the timer: I have read somewhere (datasheet maybe?) that it is good practice to have the timer running before you initially start an interrupt which I do in the setup. I then enable interrupt and turn the timer off so that I can preload and then turn it back on when I am ready to start the stopwatch.
I have tried it another way which is to setup prescale and leave timer off /then preload and when I am ready to use it I start timer with the enable interrupt on the next line, regrettably the same thing happens.
I cannot help feeling I am missing something really fundamental. This problem has been around for me for a couple of weeks now, I am ready to stich the module back into the main compilation... feeling pretty dispondent and mentally tired.... i really appeciate your input.




Bookmarks