While true
repeat
red = 1 //indicates when time delay starts
Row_3 = 0
time_delay = time_delay + 1
until
time_delay = 12000000 //about 60 seconds //6000000 //comes out as 30 seconds apx
flame1 = 1 //indicates when time_delay = 12000000
Wend
void Set_Count_Down(unsigned int count) // in mS from TMR0
{
INTCONbits.TMR0IE = 0; // stop TMR0 interrupts
flags1.COUNTDOWN_FLAG=false; // ensure not counting
Count_Down=count; // load count down
flags1.COUNTDOWN_FLAG=true; // start counting
INTCONbits.TMR0IE = 1; // and resume TMR0 interrupts
}
/*************** Timer0 ISR 1 mS ***************/
if (INTCONbits.TMR0IF)
{
INTCONbits.TMR0IF = 0; // clear Timer0 overflow flag bit
TMR0 = 6; // and reset TMR0
//TOGGLE_LED;
if (flags1.COUNTDOWN_FLAG) // if it equals true
{
if (Count_Down>0)
{
Count_Down--;
if (Count_Down<1)
{
flags1.COUNTDOWN_FLAG=false;
INTCONbits.TMR0IE = 0; // finished, so stop TMR0 interrupts
}
}
}
}
/*************** end Timer0 ISR ***************/
while(flags1.COUNTDOWN_FLAG) // wait for countdown
{
// do something
}
or
while(!flags1.COUNTDOWN_FLAG) // wait for countdown
{
// do something
}
Probably so, he never seems to listen, and never seems to take any suggestions.If you have some deja vu about this thread, starting at about message #66 in the thread 'Software PWM' may refresh your memory. Explaining timers & counters is a futile effort. It has been attempted before.
Swordfish even provides an interrupt-driven timer library routine that pretty much handles the details for youIt should be easy enough to do a BASIC version
// delay 'n' number of minutes
sub delay_minutes(n as byte)
while (n > 0)
delayms(60000) // wait 60 seconds (1 minute)
n = n - 1
end while
end sub
// examples
delay_minutes(1) // wait one minute
delay_minutes(4) // wait four minutes
I should have done a better job explaining what I need to do'
First, this is an automated sign for our town's centennial celebration come July 2023
Sequentially turn on the white lettering with 1500 ms between each letter
then have all 9 letters stay on
then wait 1 minute before turning on the red LED neon that has 3 candles that represent 100 on top of a cake.
A toggle switch enables the candle flames to light Sequentially if the toggle switch grounds portb.1
Really easy and an interrupt would just complicate matters IMO.
Have used interrupts before and yes they are handy but in this application really not necessary as all I need is a 1-minute delay before turning on the red LED neon strips.
when I am finished with the code will post
{
*****************************************************************************
* Name : UNTITLED.BAS *
* Author : [select VIEW...EDITOR OPTIONS] *
* Notice : Copyright (c) 2022 [select VIEW...EDITOR OPTIONS] *
* : All Rights Reserved *
* Date : 11/30/2022 *
* Version : 1.0 *
* Notes : *
* : *
*****************************************************************************
}
{
*****************************************************************************
* Name : UNTITLED.BAS *
* Author : [select VIEW...EDITOR OPTIONS] *
* Notice : Copyright (c) 2022 [select VIEW...EDITOR OPTIONS] *
* : All Rights Reserved *
* Date : 11/26/2022 *
* Version : 1.0 *
* Notes : *
* : *
*****************************************************************************
}
Device = 18F2221
Clock = 8
#option DIGITALIO_INIT = true// ------------------------------------tell compiler to automatically call SetAllDigital
Include "setdigitalio.bas"
Include "intosc.bas"
#option SWORDFISH_SE = true
Include "utils.bas"
Include "Convert.bas"
//Dim Time_delay As LongWord
Dim X As Byte
//12 VOLT LED STRIPS
Dim R As PORTA.0
Dim Y As PORTA.1
Dim D As PORTA.2
Dim E As PORTA.3
Dim R_1 As PORTA.4
Dim W As PORTA.5
Dim O As PORTA.6
Dim D_1 As PORTA.7
Dim Red_Candle_STRIPS As PORTB.0 //--------------------------------turn on mosfet Q10
Dim Flames As PORTB.1 //-------------------------------------------TOGGLE SWITCH PORT
//CAKE SPRINKLES CATHODES CONNECTED TO PORT PINS
Dim Row_4 As PORTB.2
Dim Row_3 As PORTB.3
Dim Row_2 As PORTB.4
Dim Row_1 As PORTB.5
//HEADLIGHT ON TRAIN ENGINE
Dim Head_light As PORTC.7
//CANDLE FLAMES
Dim Flame1 As PORTC.0
Dim Flame2 As PORTC.1
Dim Flame3 As PORTC.2
// SPRINKLES ANODES
Dim RED As PORTC.3
Dim WHITE As PORTC.4
Dim BLUE As PORTC.5
Dim GREEN As PORTC.6
Sub Sprinkles()
// CYCLE THROUGH ENABLING THE ANODES CONNECTED TO rows
// LIGHT CANDLES
//CANDLE FLAMES ON SEQUENCLY PORTC. 0,1,2
Flame1 = 1
DelayMS(2000)
Flame2 = 1
DelayMS(2000)
Flame3 = 1
//Row_1
RED = 1
WHITE=0
BLUE = 0
GREEN = 0
Row_1 = 0
Row_2 = 1
Row_3 = 1
Row_4 = 1
DelayMS(10)
Row_1 = 1
Row_2 = 0
Row_3 = 1
Row_4 = 1
DelayMS(10)
Row_1 = 1
Row_2 = 1
Row_3 = 0
Row_4 = 1
DelayMS(10)
Row_1 = 1
Row_2 = 1
Row_3 = 1
Row_4 = 0
DelayMS(10)
//ROW_2
RED = 0
WHITE=0
BLUE = 1
GREEN = 0
Row_1 = 0
Row_2 = 1
Row_3 = 1
Row_4 = 1
DelayMS(10)
Row_1 = 1
Row_2 = 0
Row_3 = 1
Row_4 = 1
DelayMS(10)
Row_1 = 1
Row_2 = 1
Row_3 = 0
Row_4 = 1
DelayMS(10)
Row_1 = 1
Row_2 = 1
Row_3 = 1
Row_4 = 0
DelayMS(10)
//ROW_3
RED = 0
WHITE=0
BLUE = 1
GREEN = 0
Row_1 = 0
Row_2 = 1
Row_3 = 1
Row_4 = 1
DelayMS(10)
Row_1 = 1
Row_2 = 0
Row_3 = 1
Row_4 = 1
DelayMS(10)
Row_1 = 1
Row_2 = 1
Row_3 = 0
Row_4 = 1
DelayMS(10)
Row_1 = 1
Row_2 = 1
Row_3 = 1
Row_4 = 0
DelayMS(10)
//ROW_4
RED = 0
WHITE=0
BLUE = 0
GREEN = 1
Row_1 = 0
Row_2 = 1
Row_3 = 1
Row_4 = 1
DelayMS(10)
Row_1 = 1
Row_2 = 0
Row_3 = 1
Row_4 = 1
DelayMS(10)
Row_1 = 1
Row_2 = 1
Row_3 = 0
Row_4 = 1
DelayMS(10)
Row_1 = 1
Row_2 = 1
Row_3 = 1
Row_4 = 0
DelayMS(10)
End Sub
Sub Candles()
If Flames = 0 Then //------------------------------------------toggle switch ON to ground
Flame1 = 1
DelayMS(1500)
Flame2 = 1
DelayMS(1500)
Flame3 = 1
EndIf
If Flames = 1 Then //--------------------------------------------toggle switch off disconnects ground
Flame1 = 0 //------------------------------------------------turn these on sequently maybe 1500ms delay between each flane
Flame2 = 0
Flame3 = 0
EndIf
End Sub
Sub Head_light_Motion() //--------------------------------------needs work to flicker
Head_light = 1
DelayMS(250)
Head_light = 0
DelayMS(400)
Head_light = 1
DelayMS(400)
End Sub
sub delay_minutes(n as byte)
while (n > 0)
delayms(60000) // wait 60 seconds (1 minute)
n = n - 1
end while
end sub
// before enabling the outputs, init all LAT registers low
LATA = 0
LATB.0 = 0
LATB.1 = 1
LATB.2 = 0
LATB.3 = 0
LATB.4 = 0
LATB.5 = 0
LATB.6 = 0
LATB.7 = 0
LATC = 0
//ENABLE OUTPUTS port A, B, C
TRISA = 0
TRISB.0 = 0
TRISB.1 = 1 //input
TRISB.2 = 0
TRISB.3 = 0
TRISB.4 = 0
TRISB.5 = 0
TRISB.6 = 0
TRISB.7 = 0
TRISC = 0
//SPRINKLES COLUMS
RED = 0
WHITE=0
BLUE = 0
GREEN = 0
Input(Flames)
// MAKE ALL THE CATHODES LOW
Row_1 = 1
Row_2 = 1
Row_3 = 1
Row_4 = 1
Head_light = 0 //-----------------------------------------------TOGGLETO SIMULATE MOVEMENT
//TURN OFF THE LETTERING
R = 0
Y = 0
D = 0
E = 0
R_1 = 0
W = 0
O = 0
D_1 = 0
//TURN OFF THE RED STRIPS
Red_Candle_STRIPS = 0
// TURN OFF FLAMES
Flame1 = 0 //portC.0
Flame2 = 0 //portC.1
Flame3 = 0 //portC.2
Input(Flames) //------------------------------------------------connects to ground via toggle switch connected to portb.1 (flames)
SetAllDigital()
While true
// Lettering comes on sequently 6 times
R = 1 //turn on lettering sequencly
DelayMS(1500)
Y = 1
DelayMS(1500)
D = 1
DelayMS(1500)
E = 1
DelayMS(1500)
R_1 = 1
DelayMS(1500)
W = 1
DelayMS(1500)
O = 1
DelayMS(1500)
D_1 = 1
DelayMS(1500)
For X = 0 To 5 //-----------------------------------------blink lettering 6 times
R = 0
Y = 0
D = 0
E = 0
R_1 = 0
W = 0
O = 0
D_1 = 0
DelayMS(1500)
R = 1
Y = 1
D = 1
E = 1
R_1 = 1
W = 1
O = 1
D_1 = 1
DelayMS(1500)
Next
Head_light_Motion() //---------------------------------------------turn on headlight
//TURN ON THE RED LED STRIPS (100 ON TOP OF CAKE)
Red_Candle_STRIPS = 1 //-----------------------------------turn on the red 100 on top of cake
delay_minutes(1)
If flames = 0 Then // ----------------------------------------------enable candle flames sequencing ONLY IF TOGGLE SWITCH IS ON (GROUND PORTb.1)
candles() //-----------------------------------------------light candles
sprinkles() // ----------------------------------------------TURNS ON CAKE SPRINKLES
End If
Wend
{
// delay 'n' number of minutes
sub delay_minutes(n as byte)
while (n > 0)
delayms(60000) // wait 60 seconds (1 minute)
n = n - 1
end while
end sub
// examples
delay_minutes(1) // wait one minute
delay_minutes(4) // wait four minutes
You can, but you probably won't like the way it works.while wiring up this sign, I realized a mistake. using IRL520 mosfets.
My mistake, can I connect the load to the source instead of the drain?
I have all my grounds for the LED neon strips connected together,
will post a schematic before I cut all the wires connected to ground.
In other words, No. The load should go in the drain side.You can, but you probably won't like the way it works.
Assuming that the gate signal is 5 volts, the source voltage will only be about 3 Volts.
{
*****************************************************************************
* Name : SequenceTimer.BAS *
* Author : For The Popcorn *
* Notice : Copyright (c) 2022 [select VIEW...EDITOR OPTIONS] *
* : All Rights Reserved *
* Date : 12/1/2022 *
* Version : 1.0 *
* Notes : This program may be used to control LED sequences: *
* : LEDs buiding from 0 to n *
* : LED chasers and marque displays *
* : Alternating LED Patterns *
*****************************************************************************
ON interval, OFF interval and OFFSET interval must be specified for each
LED in the INITIALIZE subroutine. Whatever action is requred to turn
on/off each LED must be specified in the UPDATESTATE subroutine.
The number of items(LEDs) is specified as a constant below. The timebase
is also specified as a constant, in mS - 1000 = one second.
For sequence development, debug output is available on UART1. Enable three
UART.Write lines in the ITEMISTRIGGERED subroutine to use debug.
}
Device = 18f25k22
Clock = 20
Config 'for K-series device
FOSC = HSHP ,'HS oscillator (high power > 16 MHz)
PLLCFG = Off ,'Oscillator used directly
PRICLKEN = Off ,'Primary clock can be disabled by software
FCMEN = Off ,'Fail-Safe Clock Monitor disabled
IESO = Off ,'Oscillator Switchover mode disabled
'PWRTEN = Off ,'Power up timer disabled
PWRTEN = on ,'Power up timer enabled
BOREN = Off ,'Brown-out Reset disabled in hardware and software
'BOREN = on ,'Brown-out Reset enabled
BORV = 285 ,'VBOR set to 2.85 V nominal
WDTEN = Off ,'Watch dog timer is always disabled. SWDTEN has no effect.
WDTPS = 256 ,'1:256
PBADEN = Off ,'PORTB<5:0> pins are configured as digital I/O on Reset
HFOFST = Off ,'HFINTOSC output and ready status are delayed by the oscillator stable status
MCLRE = EXTMCLR ,'MCLR pin enabled, RE3 input pin disabled
STVREN = On ,'Stack full/underflow will cause Reset
'LVP = On ,'Single-Supply ICSP enabled if MCLRE is also 1
LVP = Off ,'Single-Supply ICSP disabled
XINST = Off ,'Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
Debug = Off'Disabled
Include "utils.bas"
Include "isrtimer.bas"
Include "usart.bas"
Include "convert.bas"
Const Timer1 = 0
Const LEDon = 0
Const LEDoff = 1
Const NumberOfItems = 5 '<--- SET NUMBER OF ITEMS + 1 HERE
Const TimerBase = 100 '<--- SET THE TICK INTERVAL IN MILLISECONDS
Dim LED1 As PORTA.5 'to match LEDs on TAP-28 Plus
Dim LED2 As PORTB.3
Dim LED3 As PORTC.0
'Dim LED4 As PORTB.2 'most TAP-28 variants
Dim LED4 As PORTA.3 'TAP-28 + CH340 variant
Dim Ticks As LongWord 'interval counter, interval depends on timer interval
Dim ItemStartDelay(NumberOfItems) As LongWord 'delay from Tzero on startup
Dim ItemOnInterval(NumberOfItems) As LongWord 'number of ticks at whatever interval the
'timer is set to
Dim ItemOffInterval(NumberOfItems) As LongWord
Dim ItemTriggerTicks(NumberOfItems) As LongWord
Dim ItemIsTriggered (NumberOfItems) As Boolean
Dim ItemIsOn(NumberOfItems) As Boolean
Dim I As Byte
Sub Initialize() 'set the parameters for each item here: on time, off time
'and delayed start (offset time)
'set up the timing intervals here - 3 parameters per item
'item 1
ItemStartDelay(1)= 0 'start immediately
ItemOnInterval(1)= 10 'on time
ItemOffInterval(1)= 2 'off time
ItemTriggerTicks(1) = ItemStartDelay(1) + ItemOnInterval(1)
'item 2
ItemStartDelay(2)= 2 'offset time from item 1
ItemOnInterval(2)= 8 'turn on for 60 seconds
ItemOffInterval(2)= 4 'turn off for 30 seoonds
ItemTriggerTicks(2) = ItemStartDelay(2) + ItemOnInterval(2)
'item 3
ItemStartDelay(3)= 4 'offset from item 1
ItemOnInterval(3)= 6'turn on for 60 seconds
ItemOffInterval(3)= 6 'turn off for 30 seoonds
ItemTriggerTicks(3) = ItemStartDelay(3) + ItemOnInterval(3)
'item 4
ItemStartDelay(4)= 6 'offset from item 1
ItemOnInterval(4)= 4 'turn on for 60 seconds
ItemOffInterval(4)= 8 'turn off for 30 seoonds
ItemTriggerTicks(4) = ItemStartDelay(4) + ItemOnInterval(4)
'repeat for all items.
For I = 1 To NumberOfItems
ItemIsOn(I) = false
Next
End Sub
Public Function GetTicks() As LongWord
Timer.DisableIntr()
result = Ticks
Timer.EnableIntr()
End Function
Public Sub OnTimer()
Inc(Ticks) 'add one to the ticks counter each time timer event fires
End Sub
Sub ItemTriggered(ItemNumber As Byte)
'USART.write(DecToStr(Ticks)," Item Number: ", DecToStr(ItemNumber)) 'un-rem for debug
'ItemIsTriggered(ItemNumber) = False
If ItemIsOn(ItemNumber) = false Then
ItemIsOn(ItemNumber) = true
ItemTriggerTicks(ItemNumber) = Ticks + ItemOffInterval(ItemNumber)
'USART.write(" is off. On ticks = ", DecToStr(ItemTriggerTicks(itemnumber)), 13, 10)
Else
ItemIsOn(ItemNumber) = false
ItemTriggerTicks(ItemNumber) = Ticks + ItemOnInterval(ItemNumber)
'USART.write(" is on. Off ticks = ", DecToStr(ItemTriggerTicks(itemnumber)), 13, 10)
End If
ItemIsTriggered(ItemNumber) = false
End Sub
Sub UpdateState() 'set the LED states
'Item 1
If ItemIsOn(1) = true Then
'do what it takes to turn off
LED1 = LEDoff
Else
'do what it takes to turn on
LED1 = LEDon
End If
'Item 2
If ItemIsOn(2) = true Then
'do what it takes to turn off
LED2 = LEDoff
Else
'do what it takes to turn on
LED2 = LEDon
End If
'Item 3
If ItemIsOn(3) = true Then
'do what it takes to turn off
LED3 = LEDoff
Else
'do what it takes to turn on
LED3 = LEDon
End If
'Item 4
If ItemIsOn(4) = true Then
'do what it takes to turn off
LED4 = LEDoff
Else
'do what it takes to turn on
LED4 = LEDon
End If
'repeat for all items.
End Sub
SetBaudrate(br57600)
Initialize
SetAllDigital
Output(LED1)
Output(LED2)
Output(LED3)
Output(LED4)
LED1 = LEDon 'verify code running and LED operation
LED2 = LEDon
LED3 = LEDon
LED4 = LEDon
DelayMS(1000)
LED1 = LEDoff
LED2 = LEDoff
LED3 = LEDoff
LED4 = LEDoff
Ticks = 0 'initialize ticks count
Timer.Initialize(1)
Timer.Items(Timer1).interval = TimerBase '1000mS = 1 sec
Timer.Items(Timer1).OnTimer = @OnTimer // timer event handler
Timer.Items(Timer1).Enabled = true
Timer.Start
While 1 = 1
For I = 1 To NumberOfItems
If ItemTriggerTicks(I) = GetTicks()Then
ItemIsTriggered(I) =true
ItemTriggered(I)
End If
Next
UpdateState 'call subroutine to set LEDs
Wend
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?