Discussion forum for the BasicX family of microcontroller chips.
|
I am trying write a program that monitors 2 inputs and then activates 3 outputs. If Input #1 is active: Make output #1 follow input' AND Start 20 sec timer, at end of timer then make output #2 and #3 latch high ( if input #1 goes low before the timer reaches 20 seconds then reset the timer and wait for another input.) If input #2 is active reset latched #2 and #3 outputs all and start the main all over again. The in's and out's are easy enough but the timer section is messing me up, the section where if input #1 drops low to do a reset to the timer. Should I Task the timer and the input sections? Or just try and run all of it out of the Main? Thanks for any help, Jeff |
|
|
|
Jeff, I would do it this way. I haven't tried the code, but the basics should be there. dim IPone as byte 'input 1 dim IPtwo as byte 'input 2 dim hh as byte 'hours dim mm as byte 'minutes dim ss as single 'seconds as single dim s as byte 'whole seconds as byte dim lastsecond as byte dim timer1 as byte main() latch1 = false do call gettime(hh,nmm,ss) 'read the RTC s = fix(ss) 'get whole seconds 'this next loop only scans once per second, so is a 1 second time base 'assuming IPone & IPtwo are pulled up and go active low if (s<> lastsecond) then lastsecond = s if (IPone=0) and (IPtwo=1) then timer1 = timer1 + 1 'inc timer1 each second else timer1 = 0 end if end if 'do the outputs if (IPone=0) and (timer1<20) and (IPtwo=1) then call putpin(10,1) 'turn on output 1 call putpin(11,0) 'turn off output 2 else call putpin(10,0) ;turn off output1 call putpin(11,1) 'turn on output 2 end if loop end sub microboter wrote: > > I am trying write a program that monitors 2 inputs and then > activates 3 outputs. > > If Input #1 is active: > > Make output #1 follow input' AND > > Start 20 sec timer, at end of timer then make output #2 and #3 > > latch high ( if input #1 goes low before the timer > reaches 20 seconds then reset the timer and wait for another > input.) > > If input #2 is active reset latched #2 and #3 outputs all and start > the main all over again. > > The in's and out's are easy enough but the timer section is messing > me up, the section where if input #1 drops low to do a reset to the > timer. > > Should I Task the timer and the input sections? Or just try and run > all of it out of the Main? > Thanks for any help, > > Jeff > Yahoo! Groups Sponsor ADVERTISEMENT [Image] > > Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service. [Non-text portions of this message have been removed] |
|
Jeff, Run it all out of main. The problem is probably that you don't have enough cases in your logic for the two inputs. Are Input1 and Input2 edge or level sensitive? Edge sensitive means that you will only execute the first time they change state. Timer() is a system function which returns the time in seconds from the real time clock. The real time clock does not have to be initialized, because you are interested in elapsed time. I have made a couple of assumptions. See if this matches your logic: ----------------------------------------------------------------- Definitions for i/o pin values go here... Const Input1Pin as Byte = Const Input2Pin as Byte = Const Output1Pin as Byte = Const Output2Pin as Byte = Const Output2Pin as Byte = Dim LoopTimer as single 'used to track the 20 seconds Dim Input1 as byte Dim Input2 as byte 'Flags used to detect leading edge of Inputs going high or low 'This is needed if you want to act just one time for the input 'going high or low. Dim Input1Flag as Boolean Dim Input2Flag as Boolean Input1Flag = FALSE Input2Flag = FALSE Do Input1 = GetPin(Input1Pin) 'Read inputs 1 & 2 Input2 = GetPin(Input2Pin) 'Don't want values changing in the 'middle of the loop Call PutPin(Output1Pin, Input1) '(assumes you always want Out 1 ' tracking In 1, not just when Input#1 is ' active high as was stated) --------------------------------------------------------------------- 'Input #1 logic 'Do just one time for Input #1 going high. If (Input1 = 1) And (Input1Flag = False) then Input1Flag = True '(keeps it happening just once ' per high state) LoopTimer = Timer + 20.0 '(Start 20 second timer) ' else check to see if the input has been high for 20 seconds ' Since Timer is always running, twenty seconds after the ' step above which initialized LoopTimer to Timer plus 20.0, ' Timer will again be greater than LoopTimer. else if (Input1 = 1) and (Timer > LoopTimer) then '(20 seconds has elapsed) ' if so, set Outputs 2 and 3 high Call PutPin(Output2Pin,1) Call PutPin(Output3Pin,1) else if (Input1 = 0) then Input1Flag = False ' rearm for next time In 1 goes high LoopTimer = Timer + 20.0 ' (if input#1 is low, just ' reset timer) End If -------------------------------------------------------------------- 'Input#2 logic If (Input2 = 1) and (Input2Flag = False) then Input2Flag = True Call PutPin(Output2Pin, 0) Call PutPin(Output3Pin, 0) LoopTimer = Timer + 20.0 '(Start 20 second timer over) Else If (Input2 = 0) then (Input2Flag = False) End If -------------------------------------------------------------------- Call Delay(0.0) (let system do it's thing) Loop Be aware that this does nothing special if input 1 stays high during the time that input 2 goes high then low. In that case 20 seconds after input 2 goes high, outputs 2 and 3 will again be latched high. Ain't logic fun! <G> Andy M. --- In basicx@y..., "microboter" <jdavis211@c...> wrote: > I am trying write a program that monitors 2 inputs and then > activates 3 outputs. > > If Input #1 is active: > > Make output #1 follow input' AND > > Start 20 sec timer, at end of timer then make output #2 and #3 > latch high ( if input #1 goes low before the timer > reaches 20 seconds then reset the timer and wait for another > input.) > > If input #2 is active reset latched #2 and #3 outputs all and start > the main all over again. > > The in's and out's are easy enough but the timer section is messing > me up, the section where if input #1 drops low to do a reset to the > timer. > > Should I Task the timer and the input sections? Or just try and run > all of it out of the Main? > Thanks for any help, > > Jeff |
|
|
|
Can anybody tell me the best way to get a random number between 3 and 99 using the RND function? Thanks. David [Non-text portions of this message have been removed] |
|
|
|
From: "David E. Basile" <> > Can anybody tell me the best way to get a random number > between 3 and 99 using the RND function? The Rnd function returns a floating point number between 0 and 1, so you need to scale the number and add a bias. Something like this: Dim X As Single X = Rnd * (99.0 - 3.0) + 3.0 -- Frank Manning -- NetMedia, Inc. |