Newbie ISO of code for implementation of a counter for one-second pulses, to trigger separate interrupts for each quarter hour, e.g. 900/1800/2700.3600 pulses.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You could use the millis function. Untested code for 4 events. Just 15 minutes shown tim1 shown but same idea for tim2, etc.
#include millis.h
dim tim1,tim1event,tim2 etc as long
tim1event=15 * 60 * 1000 ;15 minutes... 900000 ms
tim1=mills
tim2=mills
tim3=mills
tim4=mills
do
if millis-tim1=tim1event then sub tim1go
loop
sub tim1go
code
end sub
Last edit: stan cartwright 2020-06-21
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Using 1ms interrupt it could be for EVERY 15 minutes that uses same code every 15 minutes.
dim millis,tim1event as long
tim1event=15 * 60 * 1000 ;15 minutes... 900000 ms
millis=0
start 1ms interrupt isr
do
if millis=tim1event then sub tim1go
loop
;
sub tim1go
code
millis=0
end sub
;
sub isr
millis=millis + 1
end sub
Last edit: stan cartwright 2020-06-21
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Here is some setup code for an interrupt on pin change, using the 1 seconcd square wave output of Dallas DS1307. I was looking to take readings every 10 sec with this example
'*****setup IOC on RA7 with pullup*****
#define SqWaveIn PortA.7 'DS1307 1Hz Square Wave Out
Dir SqWaveIn In
'wait to enable IOCIE until after startlog button press
SET IOCAP7 ON
...
...
Set IOCIE On
'start logging right away
OneSecINT = 10
StartConv = True
Main:
Do While StopLog = False
If OneSecINT = 10 Then
OneSecINT = 0
...
...
sub Interrupt
'1Hz Square Wave Out DS1307 Event Scheduler*******
If IOCAF7 = 1 Then
set IOCAF7 Off
OneSecINT += 1
'PulseOut Led, 5 ms
End If
end sub
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
If you want an RTC this version based on the millis() function may point you in the right direction:
'' SoftRTC based on the Millis() interrupt'#chip 16f18855 ' Declare the Target Processor#option explicit ' Require Explicit declaration of Variables#include <millis.h> ' Include the Library' declare working variablesDimSoftRTC_CurMs,SoftRTC_LstMsaswordSoftRTC_LstMs=0SoftRTC_CurMs=0DimSoftRTC_Hrs,SoftRTC_Min,SoftRTC_SecasByte' MainDoSoftRTC_CurMs=millis()ifSoftRTC_CurMs-SoftRTC_LstMs>999then' required Time has ElapsedSoftRTC_LstMs=SoftRTC_CurMs' Record Toggle TimeSoftRTC_UpdateendifLoopENDMacroSoftRTC_UpdateSoftRTC_Sec+=1ifSoftRTC_Sec>59thenSoftRTC_Sec=0SoftRTC_Min+=1endififSoftRTC_Min>59thenSoftRTC_Min=0SoftRTC_Hrs+=1endififSoftRTC_Hrs>23thenSoftRTC_Hrs=0EndMacro
Millis() is device independent and uses Timer0 to generate an interrupt every millisecond.
the millis() function returns the total time in mS since the last reset.
The above code converts that elapsed time into an RTC with:
SoftRTC_Hrs : SoftRTC_Min : SoftRTC_Sec
containing the current elapsed time.
User code would be needed to set the initial time and handle alarm events etc.
This is just the basic framework but should work on any device supported by GCBASIC.
Hope it helps.
Cheers
Chris
Last edit: Chris Roper 2020-06-21
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
A striped down version of the SoftRTC code above may do the trick if I understand the initial question.
This code will call a user Subroutine every 15 Min:
'' 15 MIn repeating alarm based on Millis() interrupt'#chip 16f18855 ' Declare the Target Processor and Speed#option explicit ' Require Explicit declaration of Variables#include <millis.h> ' Include the Library' declare working variablesDimSoftRTC_CurMs,SoftRTC_LstMs,SoftRTC_SecaswordSoftRTC_LstMs=0SoftRTC_CurMs=0SoftRTC_Sec=0' Main DoSoftRTC_CurMs=millis()ifSoftRTC_CurMs-SoftRTC_LstMs>999thenSoftRTC_LstMs=SoftRTC_CurMsSoftRTC_Sec+=1IfSoftRTC_Sec>899thenSoftRTC_Sec=0DoUserCodeendifendifLoopENDMacroDoUserCode' Code that runs evert 15 min' may be a macro, sub or functionEndMacro
Cheers
Chris
Last edit: Chris Roper 2020-06-21
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Newbie ISO of code for implementation of a counter for one-second pulses, to trigger separate interrupts for each quarter hour, e.g. 900/1800/2700.3600 pulses.
@Reginald. Is this a question?
You could use the millis function. Untested code for 4 events. Just 15 minutes shown tim1 shown but same idea for tim2, etc.
Last edit: stan cartwright 2020-06-21
Using 1ms interrupt it could be for EVERY 15 minutes that uses same code every 15 minutes.
dim millis,tim1event as long
tim1event=15 * 60 * 1000 ;15 minutes... 900000 ms
millis=0
start 1ms interrupt isr
do
if millis=tim1event then sub tim1go
loop
;
sub tim1go
code
millis=0
end sub
;
sub isr
millis=millis + 1
end sub
Last edit: stan cartwright 2020-06-21
@Reggie
What do you mean by an ISO code for implemention?
ISO, in search of?
Here is some setup code for an interrupt on pin change, using the 1 seconcd square wave output of Dallas DS1307. I was looking to take readings every 10 sec with this example
Thanks Kent. This seems closest to what I'm trying to do.
If you want an RTC this version based on the millis() function may point you in the right direction:
Millis() is device independent and uses Timer0 to generate an interrupt every millisecond.
the millis() function returns the total time in mS since the last reset.
The above code converts that elapsed time into an RTC with:
SoftRTC_Hrs : SoftRTC_Min : SoftRTC_Sec
containing the current elapsed time.
User code would be needed to set the initial time and handle alarm events etc.
This is just the basic framework but should work on any device supported by GCBASIC.
Hope it helps.
Cheers
Chris
Last edit: Chris Roper 2020-06-21
A striped down version of the SoftRTC code above may do the trick if I understand the initial question.
This code will call a user Subroutine every 15 Min:
Cheers
Chris
Last edit: Chris Roper 2020-06-21
original post for 1 second pulses.
not much code