|
Forum Index : Microcontroller and PC projects : RUN versus Option Autorun ON
| Author | Message | ||||
| pwillard Guru Joined: 07/06/2022 Location: United StatesPosts: 324 |
I'm having a weird issue. Using an RTC, Waveshare PICO 3.5 display and Pico Lipo... if I remove the USB POWER and then restore it... my Pico display shows incorrect time... relying on Autorun to start up... if I use a terminal program and disconnect then reconnect, hit CTRL-C to get ">" prompt and type "RUN", it works as expected. Granted... the RTC is using UTC time and I do a timezone conversion... but why would it work with manual "RUN" and fail to work with "OPTION AUTORUN ON"? (I assumed they did the same thing) |
||||
| matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 10628 |
Works for me ![]() You don't say what the "incorrect" time says |
||||
| pwillard Guru Joined: 07/06/2022 Location: United StatesPosts: 324 |
Well, an explanation of my 400 lines of code might have been in order to fully understand... but, because of that many lines... fine details were avoided. The gist of what is going on is that the RTC is set to UTC and I have a routine to deal with adjusting for timezone and a routine that figures out if DST is in place or not. (To adjust the time by an additional hour or not). When I ctrl-c and type RUN... it works as expected... but from a cold boot, it seems to want to subtract the additional hour from the timezone and an additional minute. Technically, the cold boot and warm restart should be doing the same thing. I do have some debug data output to the screen, but I can only see it AFTER I perform a CTRL-C and "RUN" but that's when it starts working right. I don't have a way to capture USB Serial on a cold start because the virtual serial port won't be connected yet. I'll see if I can find a way to share code without cluttering up this screen. Ok, I stripped out about 50% of the code. 'Program: WAVESHARE-CLOCK.bas 'Author: Pete Willard 'Version: 0.10 'Target: picomite version 'Date: 2022/06/23 'Updated: 2022/09/06 'Time: 08:34 AM 'Notes: USING PIMORONI LIPO BOARD WITH WAVESHARE Pico-ResTouch-LCD-3.5 ' and DS3231 I2C Real Time Clock (generic module) ' DATE format has support for USA style ;-P ' 'Reference: Too numerous to list ' ' EDT = Time in NYC is UTC-4 ' EST = Time in NYC is UTC-5 ' ' Eastern Daylight Time - (EDT) From the second Sunday in March 2:00AM until the ' first Sunday in November 2:00A (also known as Daylight Savings Time - DST) ' ' Eastern Standard Time - (EST) From the first Sunday in November 2:00AM until the ' second Sunday in March 2:00 AM ' ' '=====[ CONFIGURATION ]========================================================== 'OPTION SYSTEM SPI GP10,GP11,GP12 'OPTION SYSTEM I2C GP4,GP5 'OPTION AUTORUN ON 'OPTION COLOURCODE ON 'OPTION DISPLAY 25, 132 'OPTION LCDPANEL ILI9488W, RLANDSCAPE,GP8,GP15,GP9,GP13 ' To place the USB topside 'OPTION GUI CONTROLS 75 'OPTION TOUCH GP16,GP17 'GUI CALIBRATE 0, 3998, 211, -1268, 884 'OPTION SDCARD GP22 '=== Option DEFAULT INTEGER Option EXPLICIT '=====[ CONSTANTS ]============================================================== Const Background = RGB(BLACK) Const LIGHT = RGB(WHITE) Const AMBER = RGB(211,191,0) Const L.GREEN = RGB(48, 112, 30) Dim integer TIMEZONE = -4 ' STANDARD TIME '=====[ Variables ]============================================================= Dim string FullTime$ Dim integer Sunday.Count Dim INTEGER DST = 0 ' True or False Dim STRING LastTime$ = "" Dim STRING HHMM$ Dim INTEGER AMPM Dim STRING MyDate$ Dim INTEGER SHOWTIME = 1 ' fonts Dim integer f1=3,f2=1 Dim integer clock.hour, clock.minute, clock.day Dim INTEGER USA = 1 ' 1 = USA Date Format, 0 = format for everyone else '====[ PINS]===================================================================== GUI INTERRUPT MyInt '=====[ SETUP ]================================================================== ' on boot, get time from RTC and setup a regular update inteval Sub STARTUP 'RTC GETTIME rtcsettime SetTick 7200000, RtcSetTime ' 2 hours Print "Time:"; Time$ Print "Date:";Date$ EndIf End Sub '====[ Interrupt ]============================================================== Sub MyInt Print Touch(x) Touch(y) End Sub '=====[ MAIN CODE ]============================================================== CLS STARTUP ' Default Text Color and Font Size Colour AMBER,Background Font f2 Backlight 60 ' Tight Loop ' Update Time on screen only when HH:MM changes, every 60 seconds Do Font f1,2 HHMM$ = Left$(Time$,5) If LastTime$ <> HHMM$ Then UpdateClock Loop '================================================================================ '================================================================================ Sub RTCSETTIME ' retreive time from the Real Time Clock ' Sets TIME$ and DATE$ variables SETDST RTC GETTIME Local STRING TheTime$ = Left$(Time$,5) Local hour = Val(Left$(TheTime$,2)) Local second = Val(Right$(TheTime$,2)) Local minute = Val(Mid$(TheTime$,4,2)) Print "UTC Hour= ";hour If DST = 0 Then TIMEZONE = TIMEZONE -1 hour = hour + TIMEZONE Print "Adjusted Hour = ";hour Time$ = Str$(hour) + ":" + Str$(minute) +":"+ Str$(Second) Print "Adjusted to ";Time$ End Sub '===== Sub UpdateClock ' Note: ALARMS are always set with 24 Hour time. ' Display is always 12 Hr AM/PM Print "Update time: " Time$ LastTime = Left$(Time$,5) Local hour = Val(Left$(lastTime$,2)) Local minute = Val(Right$(lastTime$,2)) Local meridian = hour Local AmPm$ Local HH$,MM$ ' Check if AM or PM If meridian >= 12 Then meridian = meridian - 12 AMPM$ = "PM" Else AMPM$ = "AM" EndIf ' Handle 12 AM, avoid 0 O'clock. If meridian = 0 Then meridian = 12 ' Reassemble the TIME variables back into a string value ' with leading zero blanking HH$ = Str$(meridian) If Meridian < 10 Then HH$ = " " + HH$ HH$ = HH$ + ":" MM$ = Str$(Minute) If minute < 10 Then MM$ = "0" + MM$ HHMM$ = HH$ + MM$ ' Update the screen ' with ability to blank the time. If SHOWTIME = 1 Then Text (MM.HRes/2 -50), MM.VRes/4, HHMM$, "CM", 6, 2 ' TIME Text MM.HRes -50, MM.VRes/4 +10, AMPM$, "R" ' AM/PM GET_DATE EndIf End Sub '=== Sub SETDST ' New York, Usa, Time Zone ' Figure Out Eastern Daylight Time By Finding ' The Day Of The Month Of The Second Sunday In March ' and the Day of the month in the first Sunday in November ' Then determine if the current date is within the DST range ' Set DST to 1 or 0 accordingly Local Myyear$ = Mid$(Date$,7) Local Dst.Addday = 0 ' In the loop, We Start With An Increment, So Begin With 0 Local Dst.Start$ = "" ' Will contain the DST Start Date Local DST.End$ = "" ' Will contain the DST End Date Local Dst.Sunday$ = "" ' Sunday String matching Local Dst.Countsunday = 0 ' Looking for sundays as we increment days Local Day1, Day2 ' Day of the week ' Compute DST Start Do Inc Dst.Addday ' Pad Day To Make Day$() Happy if needed If Dst.Addday < 10 Then Dst.Start$ = "0" +Str$(Dst.Addday) + "-03-" + Myyear$ Else Dst.Start$ = Str$(Dst.Addday) + "-03-" + Myyear$ EndIf Dst.Sunday$ = Day$(Dst.Start$) If Dst.Sunday$ = "Sunday" Then Inc Dst.Countsunday EndIf Loop Until Dst.Countsunday = 2 Day1 = DST.AddDay 'compute DST End DST.AddDay = 0 DST.CountSunday = 0 Do Inc Dst.Addday ' Pad Day To make Day$() happy since day will always be a low number Dst.End$ = "0" +Str$(Dst.Addday) + "-11-" + Myyear$ Dst.Sunday$ = Day$(Dst.End$) If Dst.Sunday$ = "Sunday" Then Inc Dst.Countsunday EndIf Loop Until Dst.Countsunday = 1 Day2 = DST.AddDay '' Print Results 'Print "Second Sunday In March Is Day:" Day1 'Print "First Sunday In November Is Day:" Day2 Dst.Start$ = Str$(Day1) + "-03-" + Myyear$ +" 02:00:00" 'print "Current Epoch Time " EPOCH(NOW) 'print "DST START Value " DST.Start$ 'print "DST START Epoch Time " EPOCH(DST.Start$) Dst.End$ = "0" +Str$(DAY2) + "-11-" + Myyear$ + " 02:00:00" 'print "DST END Value " DST.END$ 'print "DST END Epoch Time " EPOCH(DST.END$) ' Set DST STATE If Epoch(NOW) < Epoch(DST.START$) Then DST = 0 If Epoch(NOW) > Epoch(DST.START$) Then DST = 1 If Epoch(NOW) > Epoch(DST.END$) Then DST = 0 Print "DST STATE = " DST End Sub '=== Sub GET_DATE ' Uses DAY$() to get weekday ' Fix the date notation for the weird Americans Local MyDay$ = Left$(Date$,2) Local MyMonth$ = Mid$(Date$,4,2) Local MyYear$ = Mid$(Date$,7) ' Avengers Assemble If USA Then MyDate$ = MyMonth$ +"/"+ MyDay$ +"/"+ MyYear$ Else MyDate$ = MyDay$ +"/"+ MyMonth$ +"/"+ MyYear$ EndIf ' Pad the Weekday string so we always clear what was already there ' on the screen Text MM.HRes/2,MM.VRes/2+15,PadString$(10,Day$(NOW)),"CM" Text MM.HRes/2, MM.VRes*3/4-15, MyDate$, "CM" End Sub '=== ' Add leading and trailing spaces to a string for a given size Function PadString$(size,S$) Local pad = size/2 PadString$ = s$ If Len(padstring$) >= size Then padstring$ = s$ Else padstring$ = String$(pad," ") + S$ + String$(pad," ") EndIf End Function '=== ' x=Constrain(TriggerTemp,7,10) Function Constrain(v As Integer,Llim As Integer, Ulim As Integer) As Integer Constrain=Min(Max(v,Llim ),Ulim ) End Function '================================================================================ Edited 2022-09-07 04:24 by pwillard |
||||
| matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 10628 |
It is a bug in your code. You are calling GETDST before RTC GETIME. Swap lines 206 and 207 in the code you PM'd. Works after ctrl-C because the time/date is already set. What is the MP3 module you are using? Edited 2022-09-07 04:30 by matherp |
||||
| pwillard Guru Joined: 07/06/2022 Location: United StatesPosts: 324 |
Man... you can become so blind to your own code sometimes. Thanks I'm using the Sparkfun qwiic MP3 Trigger. MP3Trigger |
||||
| The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |