each 100th is 10ms on the i/o debug section btw
each 100th is 10ms on the i/o debug section btw
My output pin changes state every 2.5ms at 64MHz.
Code:'*************************************************************************** '* Name : Elapsed_INT-18.bas * '* Author : Darrel Taylor * '* Date : JUL 11, 2006 : 7/11/2010 * '* Version : 1.2 * '* Notes : Must have DT_INTS-18.bas loaded first * '* ver 1.2: Now works at any OSC frequency without using the prescaler * '*************************************************************************** DISABLE DEBUG ; syntax = Handler IntSource, Label, Type, ResetFlag? DEFINE Elapsed_Handler TMR1_INT, _ClockCount, asm, yes ; the above define can be used in the INT_LIST macro, if desired (optional) EL_Ticks VAR BYTE ; Counts timer Overflows EL_100th VAR BYTE ;T1Post VAR BYTE ; Timer1 postscaler EL_Seconds VAR BYTE EL_Minutes VAR BYTE EL_Hours VAR BYTE EL_Days VAR WORD EL_100thChanged VAR BIT EL_SecondsChanged VAR BIT ; idicates that the value has changed EL_MinutesChanged VAR BIT EL_HoursChanged VAR BIT EL_DaysChanged VAR BIT GOSUB ResetTime ; initialize the Elapsed Timer Goto OverElapsed ; skip over the routines ' -------------- calc timer reload Constants ------------------------------- ASM T1PS = 1 ; start with 1:1 postscaler TimerConst = ((OSC*1000000)/4/100) ; how many timer ticks will it take while TimerConst > 65400 ; if it's more than the timer can count T1PS = T1PS * 2 ; double the postscaler TimerConst = TimerConst / 2 ; halve the count endw TimerConst = 65536 - TimerConst + 8 ; final reload value ; ----------------- ADD TimerConst to TMR1H:TMR1L ------------------------- ADD2_TIMER macro BCF T1CON,TMR1ON, 0 ; 1 Turn off timer MOVLW LOW(TimerConst) ; 1 ADDWF TMR1L,F, 0 ; 1 BTFSC STATUS,C ; 1/2 INCF TMR1H,F, 0 ; 1 MOVLW HIGH(TimerConst) ; 1 ADDWF TMR1H,F, 0 ; 1 endm ; ----------------- ADD TimerConst to TMR1H:TMR1L and restart TIMER1 ------ RELOAD_TIMER macro ADD2_TIMER BSF T1CON,TMR1ON, 0 ; 1 Turn TIMER1 back on (8 cycles) endm ; ----------------- Load TimerConst into TMR1H:TMR1L ---------------------- LOAD_TIMER macro MOVE?CT 0, T1CON,TMR1ON MOVE?CB 0, TMR1L MOVE?CB 0, TMR1H ADD2_TIMER endm ENDASM ' ------[ This is the Interrupt Handler ]----------------------------------- T1PS CON EXT ClockCount: @ RELOAD_TIMER ; Reload TIMER1 EL_Ticks = EL_Ticks + 1 ; each tick is 2.5ms IF LATD.3 = 0 THEN ' debug LATD.3 = 1 ELSE LATD.3 = 0 ENDIF if EL_ticks // T1PS = 0 THEN ' if modulas of tips (4) = 0 IF LATD.3 = 0 THEN ' debug LATD.3 = 1 ELSE LATD.3 = 0 ENDIF EL_100th = EL_100th + 1 EL_100thChanged = 1 IF EL_100TH = 100 THEN EL_100TH = 0 EL_Seconds = EL_Seconds + 1 EL_SecondsChanged = 1 IF EL_Seconds = 60 THEN EL_Seconds = 0 EL_Minutes = EL_Minutes + 1 EL_MinutesChanged = 1 eNDIF IF EL_Minutes = 60 THEN EL_Minutes = 0 EL_Hours = EL_Hours + 1 EL_HoursChanged = 1 ENDIF IF EL_Hours = 24 THEN EL_Hours = 0 EL_Days = EL_Days + 1 EL_DaysChanged = 1 ENDIF eNDIF endif ' Ticks = Ticks + 1 ' IF Ticks = 100 THEN ' Ticks = 0 ' T1Post = T1Post + 1 ' IF T1Post = T1PS THEN ' T1Post = 0 ' Seconds = Seconds + 1 ' SecondsChanged = 1 ' IF Seconds = 60 THEN ' Seconds = 0 ' Minutes = Minutes + 1 ' MinutesChanged = 1 ' ENDIF ' IF Minutes = 60 THEN ' Minutes = 0 ' Hours = Hours + 1 ' HoursChanged = 1 ' ENDIF ' IF Hours = 24 THEN ' Days = Days + 1 ' DaysChanged = 1 ' Hours = 0 ' ENDIF ' ENDIF ' ENDIF @ INT_RETURN ; Restore context and return from interrupt '-----====[ END OF TMR1 Interrupt Handler ]====----------------------------- StartTimer: T1CON = 1 ; 1:1, FOSC4, TMR1ON RETURN ; -------------------------------------------------------------------------- StopTimer: T1CON.0 = 0 ; Turn OFF Timer1 RETURN ; -------------------------------------------------------------------------- BitSave VAR BIT ResetTime: BitSave = T1CON.0 ; Save TMR1ON bit @ LOAD_TIMER ; Load TimerConst T1CON.0 = BitSave ; Restore TMR1ON bit ; T1Post = 0 ; clear the postscaler EL_Ticks = 0 EL_100th = 0 EL_Seconds = 0 EL_Minutes = 0 EL_Hours = 0 EL_Days = 0 EL_100thChanged = 1 EL_SecondsChanged = 1 ; indicate everything has changed EL_MinutesChanged = 1 ; so that 00:00:00 is processed EL_HoursChanged = 1 EL_DaysChanged = 1 RETURN OverElapsed: ENABLE DEBUG
My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.
Not as dumb as yesterday, but stupider than tomorrow!
Yes, I'm an idiot.
T1CON becomes 00000001 once it is STARTED! D'OH!
My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.
Not as dumb as yesterday, but stupider than tomorrow!
Sheldon,
It's not perfect, I'm missing some pulses on the Saleae probe, but it's sticking to a 2.5ms tick as you describe in your Elapsed include comment.
EDIT: I just noticed that the skipped pulse happens at every 4 ticks.
And that skipped pulse is between 20-21uS.
EDIT SOME MORE: Got it, it's that 2nd LED toggle. I commented it out and now I have a regular 2.5ms pulse.
Robert
Last edited by Demon; - 23rd December 2014 at 04:43.
My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.
Not as dumb as yesterday, but stupider than tomorrow!
My output pin changes state every 2.5ms at 64MHz.
Code:'*************************************************************************** '* Name : Elapsed_INT-18.bas * '* Author : Darrel Taylor * '* Date : JUL 11, 2006 : 7/11/2010 * '* Version : 1.2 * '* Notes : Must have DT_INTS-18.bas loaded first * '* ver 1.2: Now works at any OSC frequency without using the prescaler * '*************************************************************************** DISABLE DEBUG ; syntax = Handler IntSource, Label, Type, ResetFlag? DEFINE Elapsed_Handler TMR1_INT, _ClockCount, asm, yes ; the above define can be used in the INT_LIST macro, if desired (optional) EL_Ticks VAR BYTE ; Counts timer Overflows EL_100th VAR BYTE ;T1Post VAR BYTE ; Timer1 postscaler EL_Seconds VAR BYTE EL_Minutes VAR BYTE EL_Hours VAR BYTE EL_Days VAR WORD EL_100thChanged VAR BIT EL_SecondsChanged VAR BIT ; idicates that the value has changed EL_MinutesChanged VAR BIT EL_HoursChanged VAR BIT EL_DaysChanged VAR BIT GOSUB ResetTime ; initialize the Elapsed Timer Goto OverElapsed ; skip over the routines ' -------------- calc timer reload Constants ------------------------------- ASM T1PS = 1 ; start with 1:1 postscaler TimerConst = ((OSC*1000000)/4/100) ; how many timer ticks will it take while TimerConst > 65400 ; if it's more than the timer can count T1PS = T1PS * 2 ; double the postscaler TimerConst = TimerConst / 2 ; halve the count endw TimerConst = 65536 - TimerConst + 8 ; final reload value ; ----------------- ADD TimerConst to TMR1H:TMR1L ------------------------- ADD2_TIMER macro BCF T1CON,TMR1ON, 0 ; 1 Turn off timer MOVLW LOW(TimerConst) ; 1 ADDWF TMR1L,F, 0 ; 1 BTFSC STATUS,C ; 1/2 INCF TMR1H,F, 0 ; 1 MOVLW HIGH(TimerConst) ; 1 ADDWF TMR1H,F, 0 ; 1 endm ; ----------------- ADD TimerConst to TMR1H:TMR1L and restart TIMER1 ------ RELOAD_TIMER macro ADD2_TIMER BSF T1CON,TMR1ON, 0 ; 1 Turn TIMER1 back on (8 cycles) endm ; ----------------- Load TimerConst into TMR1H:TMR1L ---------------------- LOAD_TIMER macro MOVE?CT 0, T1CON,TMR1ON MOVE?CB 0, TMR1L MOVE?CB 0, TMR1H ADD2_TIMER endm ENDASM ' ------[ This is the Interrupt Handler ]----------------------------------- T1PS CON EXT ClockCount: @ RELOAD_TIMER ; Reload TIMER1 EL_Ticks = EL_Ticks + 1 ; each tick is 2.5ms IF LATD.3 = 0 THEN ' debug LATD.3 = 1 ELSE LATD.3 = 0 ENDIF if EL_ticks // T1PS = 0 THEN ' if modulas of tips (4) = 0 IF LATD.3 = 0 THEN ' debug LATD.3 = 1 ELSE LATD.3 = 0 ENDIF EL_100th = EL_100th + 1 EL_100thChanged = 1 IF EL_100TH = 100 THEN EL_100TH = 0 EL_Seconds = EL_Seconds + 1 EL_SecondsChanged = 1 IF EL_Seconds = 60 THEN EL_Seconds = 0 EL_Minutes = EL_Minutes + 1 EL_MinutesChanged = 1 eNDIF IF EL_Minutes = 60 THEN EL_Minutes = 0 EL_Hours = EL_Hours + 1 EL_HoursChanged = 1 ENDIF IF EL_Hours = 24 THEN EL_Hours = 0 EL_Days = EL_Days + 1 EL_DaysChanged = 1 ENDIF eNDIF endif ' Ticks = Ticks + 1 ' IF Ticks = 100 THEN ' Ticks = 0 ' T1Post = T1Post + 1 ' IF T1Post = T1PS THEN ' T1Post = 0 ' Seconds = Seconds + 1 ' SecondsChanged = 1 ' IF Seconds = 60 THEN ' Seconds = 0 ' Minutes = Minutes + 1 ' MinutesChanged = 1 ' ENDIF ' IF Minutes = 60 THEN ' Minutes = 0 ' Hours = Hours + 1 ' HoursChanged = 1 ' ENDIF ' IF Hours = 24 THEN ' Days = Days + 1 ' DaysChanged = 1 ' Hours = 0 ' ENDIF ' ENDIF ' ENDIF @ INT_RETURN ; Restore context and return from interrupt '-----====[ END OF TMR1 Interrupt Handler ]====----------------------------- StartTimer: T1CON = 1 ; 1:1, FOSC4, TMR1ON RETURN ; -------------------------------------------------------------------------- StopTimer: T1CON.0 = 0 ; Turn OFF Timer1 RETURN ; -------------------------------------------------------------------------- BitSave VAR BIT ResetTime: BitSave = T1CON.0 ; Save TMR1ON bit @ LOAD_TIMER ; Load TimerConst T1CON.0 = BitSave ; Restore TMR1ON bit ; T1Post = 0 ; clear the postscaler EL_Ticks = 0 EL_100th = 0 EL_Seconds = 0 EL_Minutes = 0 EL_Hours = 0 EL_Days = 0 EL_100thChanged = 1 EL_SecondsChanged = 1 ; indicate everything has changed EL_MinutesChanged = 1 ; so that 00:00:00 is processed EL_HoursChanged = 1 EL_DaysChanged = 1 RETURN OverElapsed: ENABLE DEBUG
My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.
Not as dumb as yesterday, but stupider than tomorrow!
Yup, I get 10ms if I comment out the 1st LED toggle.
Attachment 7542
I understand quickly as long as you explain 10 times.
Robert
My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.
Not as dumb as yesterday, but stupider than tomorrow!
Well that toggle from Sheldon confirms DT's is not working perfectly at 64MHz.
I get 2.5ms on each LED toggle.
Thanks a lot Sheldon for having figured this one out.Code:T1PS CON EXT ClockCount: @ RELOAD_TIMER ; Reload TIMER1 Ticks = Ticks + 1 IF LATD.3 = 0 THEN ' debug LATD.3 = 1 ELSE LATD.3 = 0 ENDIF IF Ticks = 100 THEN Ticks = 0 T1Post = T1Post + 1 IF T1Post = T1PS THEN T1Post = 0 Seconds = Seconds + 1 SecondsChanged = 1 IF Seconds = 60 THEN Seconds = 0 Minutes = Minutes + 1 MinutesChanged = 1 ENDIF IF Minutes = 60 THEN Minutes = 0 Hours = Hours + 1 HoursChanged = 1 ENDIF IF Hours = 24 THEN Days = Days + 1 DaysChanged = 1 Hours = 0 ENDIF ENDIF ENDIF @ INT_RETURN ; Restore context and return from interrupt
Robert
GAAAAA must not click on MeProg PROGRAM icon when I want to click on POST, it won't work.
My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.
Not as dumb as yesterday, but stupider than tomorrow!
now I'm confused
orWell that toggle from Sheldon confirms DT's is not working perfectly at 64MHz.
Well that toggle from Sheldon confirms DT's is working perfectly at 64MHz.
ps
can be replaced withIF LATD.3 = 0 THEN ' debug
LATD.3 = 1
ELSE
LATD.3 = 0
ENDIF
latd.3=!latd.3
lets not have too much unnecessary overhead in the interrupt
Last edited by richard; - 23rd December 2014 at 05:20.
My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.
Not as dumb as yesterday, but stupider than tomorrow!
you may like to re-examine that I just tried it on a pic1845k20 @64 MHz and the int is @2.5mS as expected , sheldons mod just adds 100th capability doesn't it ?
the seconds inc on every 400th interrupt the ticks are not meant to be 10mS
Last edited by richard; - 23rd December 2014 at 05:57. Reason: better explanition
From http://web.archive.org/web/201206151...8/elapsed.html
But a tick is not 2.5ms.The time is kept in the variables:
--------------------------------------------------------------------------------
Ticks var byte ' 1/100th of a second
Seconds var byte ' 0-59
Minutes var byte ' 0-59
Hours var byte ' 0-23
Days var word ' 0-65535
Robert
What happens when you start/stop the timer after 5 ticks using the original include?
I get this using the new include:
RobertCode:MainProgram: if T1CON.0 = 0 then PortD.3 = 1 GOSUB StartTimer endif if OneHundreth = 5 then PortD.3 = 0 GOSUB StopTimer ' Stop the Elapsed Timer GOSUB ResetTime ' Reset Time to 0d-00:00:00.00 endif goto MainProgram
New version of Darrel Taylor's Elapsed include for 64MHz:
New field OneHundreth (10ms) replaces Tick (2.5ms at 64MHz).Code:'*************************************************************************** '* Name : Elapsed_INT-18.bas * '* Author : Darrel Taylor * '* Date : JUL 11, 2006 : 7/11/2010 : Dec 23, 2014 * '* Version : 1.3 * '* Notes : Must have DT_INTS-18.bas loaded first * '* ver 1.2: Now works at any OSC frequency without using the prescaler * '* ver 1.3: will work with 64MHz thanks to Sheldon * '* New field ONEHUNDRETH is now used instead of TICKS * '*************************************************************************** DISABLE DEBUG ; syntax = Handler IntSource, Label, Type, ResetFlag? DEFINE Elapsed_Handler TMR1_INT, _ClockCount, asm, yes ; the above define can be used in the INT_LIST macro, if desired (optional) Ticks VAR BYTE ; Counts timer Overflows OneHundreth VAR BYTE ; New field for 64MHz ;T1Post VAR BYTE ; Timer1 postscaler Seconds VAR BYTE Minutes VAR BYTE Hours VAR BYTE Days VAR WORD OneHundrethChanged VAR BIT ; New field for 64MHz SecondsChanged VAR BIT ; idicates that the value has changed MinutesChanged VAR BIT HoursChanged VAR BIT DaysChanged VAR BIT GOSUB ResetTime ; initialize the Elapsed Timer Goto OverElapsed ; skip over the routines ' -------------- calc timer reload Constants ------------------------------- ASM T1PS = 1 ; start with 1:1 postscaler TimerConst = ((OSC*1000000)/4/100) ; how many timer ticks will it take while TimerConst > 65400 ; if it's more than the timer can count T1PS = T1PS * 2 ; double the postscaler TimerConst = TimerConst / 2 ; halve the count endw TimerConst = 65536 - TimerConst + 8 ; final reload value ; ----------------- ADD TimerConst to TMR1H:TMR1L ------------------------- ADD2_TIMER macro BCF T1CON,TMR1ON, 0 ; 1 Turn off timer MOVLW LOW(TimerConst) ; 1 ADDWF TMR1L,F, 0 ; 1 BTFSC STATUS,C ; 1/2 INCF TMR1H,F, 0 ; 1 MOVLW HIGH(TimerConst) ; 1 ADDWF TMR1H,F, 0 ; 1 endm ; ----------------- ADD TimerConst to TMR1H:TMR1L and restart TIMER1 ------ RELOAD_TIMER macro ADD2_TIMER BSF T1CON,TMR1ON, 0 ; 1 Turn TIMER1 back on (8 cycles) endm ; ----------------- Load TimerConst into TMR1H:TMR1L ---------------------- LOAD_TIMER macro MOVE?CT 0, T1CON,TMR1ON MOVE?CB 0, TMR1L MOVE?CB 0, TMR1H ADD2_TIMER endm ENDASM ' ------[ This is the Interrupt Handler ]----------------------------------- T1PS CON EXT ClockCount: @ RELOAD_TIMER ; Reload TIMER1 Ticks = Ticks + 1 ; each tick is 2.5ms ' IF LATD.3 = 0 THEN ' used to debug to confirm 2.5ms ' LATD.3 = 1 ' ELSE ' LATD.3 = 0 ' ENDIF if ticks // T1PS = 0 THEN ' if modulas of tips (4) = 0 ' IF LATD.3 = 0 THEN ' used to debug to confirm 10ms ' LATD.3 = 1 ' ELSE ' LATD.3 = 0 ' ENDIF OneHundreth = OneHundreth + 1 ; each 1/100th is 10ms OneHundrethChanged = 1 IF OneHundreth = 100 THEN OneHundreth = 0 ' Ticks = Ticks + 1 ' IF Ticks = 100 THEN ' Ticks = 0 ' T1Post = T1Post + 1 ' IF T1Post = T1PS THEN ' T1Post = 0 Seconds = Seconds + 1 SecondsChanged = 1 IF Seconds = 60 THEN Seconds = 0 Minutes = Minutes + 1 MinutesChanged = 1 ENDIF IF Minutes = 60 THEN Minutes = 0 Hours = Hours + 1 HoursChanged = 1 ENDIF IF Hours = 24 THEN Days = Days + 1 DaysChanged = 1 Hours = 0 ENDIF ENDIF ENDIF @ INT_RETURN ; Restore context and return from interrupt '-----====[ END OF TMR1 Interrupt Handler ]====----------------------------- StartTimer: T1CON = 1 ; 1:1, FOSC4, TMR1ON RETURN ; -------------------------------------------------------------------------- StopTimer: T1CON.0 = 0 ; Turn OFF Timer1 RETURN ; -------------------------------------------------------------------------- BitSave VAR BIT ResetTime: BitSave = T1CON.0 ; Save TMR1ON bit @ LOAD_TIMER ; Load TimerConst T1CON.0 = BitSave ; Restore TMR1ON bit ; T1Post = 0 ; clear the postscaler Ticks = 0 OneHundreth = 0 Seconds = 0 Minutes = 0 Hours = 0 Days = 0 OneHundrethChanged = 1 SecondsChanged = 1 ; indicate everything has changed MinutesChanged = 1 ; so that 00:00:00 is processed HoursChanged = 1 DaysChanged = 1 RETURN OverElapsed: ENABLE DEBUG
(Remove .TXT suffix)
Elapsed_INT-18_64MHz.bas.txt
Robert
My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.
Not as dumb as yesterday, but stupider than tomorrow!
Bookmarks