that looked wrong at first if address started a 1600 but it doesn't.for tempvar=0 to 105
address=tempvar<<3
perhaps address gets corrupted every time readout is run,
spaghetti code like that is hard to unravel
that looked wrong at first if address started a 1600 but it doesn't.for tempvar=0 to 105
address=tempvar<<3
perhaps address gets corrupted every time readout is run,
spaghetti code like that is hard to unravel
Last edited by richard; - 4th September 2024 at 05:59.
Warning I'm not a teacher
I'm not saying this is related to your problem but here:
This will "hold" until TMR1H is 128 and then countinue.Code:hold1: tempbyt=TMR1H if tempbyt<>128 then hold1
But for how long is TMR1H 128? Are you sure it's not (still) 128 the next time you check?
I would rewrite this.
* For pacing the loop, poll the TMR1 interrupt flag.
* Create a short subroutine for each "task". MeasureA, MeasureB, MeasureC, WriteEEPROM and so on.
* Have a LoopCount variable that counts from 0 to whatever.
* Use a Select Case block to execute whatever tasks are needed at each increment of the loop.
Crude example:Code:TMR1IF VAR PIR1.0 LoopCount VAR BYTE TMR1IF = 0 T1CON = %00110001 ' Prescaler = 1:8, Timer ON Main: IF TMR1IF=0 THEN Main ' Wait for TMR1 roll over TMR1IF=0 ' Reset interrupt flag. Select Case LoopCount Case 0 GOSUB MeasureA GOSUB MeasureB Case 1 GOSUB MeasureA GOSUB MeasureC Case 2 GOSUB MeasureA GOSUB MeasureB GOSUB MeasureC Case 3 GOSUB MeasureB GOSUB MeasureC GOSUB WriteEEPROM END SELECT LoopCount = LoopCount + 1 IF LoopCount = 4 THEN LoopCount = 0 Goto Main MeasureA: ' Do stuff RETURN MeasureB: ' Do Stuff RETURN MeasureC: ' Do Stuff RETURN WriteEEPROM: ' Do Stuff RETURN
i had a slightly different take but am amazed at the similarity
Code:#CONFIG __config _CONFIG1, _HS_OSC & _WDT_OFF & _MCLRE_OFF & _LVP_OFF & _CP_OFF __CONFIG _CONFIG2, _WRT_OFF & _BOR21V #ENDCONFIG DEFINE INTHAND ticker ANSEL=0 'all analogue ports to digital ANSELH=0 'all analogue ports to digital TRISA=%00101011 '(0=output, 1=input) TRISB=%00100001 '(0=output, 1=input) TRISC=%00000000 '(0=output, 1=input) TRISE=%00001000 '(0=output, 1=input) OPTION_REG=%11000101 PIN_OUT var PORTC.3 'serial out pin LED var portA.2 wsave var byte $70 SYSTEM ssave var byte SYSTEM psave var byte SYSTEM taskflag var byte taskswitch var byte ro_counter var byte ibit var byte address var word icount var word define OSC 20 intcon =$c0 pir1.0=0 pie1.0=1 serout2 PIN_OUT,32,["THERMAL START",13,10] '19200bps T1CON=$31 main: if taskflag then taskflag = 0 taskswitch = taskswitch + 1 if taskswitch == 4 then taskswitch = 0 select case taskswitch CASE 0 gosub task0 serout2 PIN_OUT,32,["A",dec ibit,"-",dec icount,"-",dec address,13,10] serout2 PIN_OUT,32,["B",dec ibit,"-",dec icount,"-",dec address,13,10] case 1 gosub task1 icount=icount+1 serout2 PIN_OUT,32,["C",dec ibit,"-",dec icount,"-",dec address,13,10] address=address+16 serout2 PIN_OUT,32,["D",dec ibit,"-",dec icount,"-",dec address,13,10] case 2 gosub task2 ro_counter =ro_counter +1 if ro_counter == 16 then serout2 PIN_OUT,32,["READOUT",13,10] ro_counter =0 endif case 3 gosub task3 end select endif goto main task0: 'do voltage stuff return task1: 'do current stuff return task2: 'do other stuff return task3: LED = ! led return END asm ticker ;tmr1 isr banksel _taskflag bsf _taskflag,0 banksel PIR1 bcf PIR1,0 movf psave,W ; restore PCLATH movwf PCLATH swapf ssave,W ; restore STATUS movwf STATUS swapf wsave,F ; restore W (swap avoids changing STATUS) swapf wsave,W RETFIE endasm
Warning I'm not a teacher
Bookmarks