Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

pass the TIME away

Status
Not open for further replies.
... and for those of you playing at home extra points are awarded for figuring out
why this part of the code is a bad idea:
Code:
dim mS as word = 0          // this is the timer count value. initialize it to 0 on startup
dim StartTime, EndTime as word    // these are for the first elapsed time

// OnTimer event
event OnTimer()
    Inc(mS)
end event

StartTime = mS
EndTime = mS

hint- the OnTimer event is called by the timer ISR
 
I discovered all that you mentioned.
am using swordfish version 2.2.3.0
got sidtracked, our heat pump decoded to quit.
 
Why does anyone try to help this guy - yes, I know, nice guys. He deliberately misinterprets anything said. He's a complete troll or will never learn anything, so stop trying.

Mike.
 
If trying to install a printer keeps bringing up the install for a CD ROM, you must have the wrong install package.

You said the model number of your printer is p110w, which doesn't seem to exist. Nigel concluded you made a typo and actually have a P1102W, which may or may not be correct.

I suggest you get a bright light and a magnifying glass and determine what the actual model number is. It may be that the printer is ancient and not supported by your version of Windows, in which case your option is "forget about it", but if you search on the actual part number, you should be able to get the correct install package.
 
If trying to install a printer keeps bringing up the install for a CD ROM, you must have the wrong install package.

You said the model number of your printer is p110w, which doesn't seem to exist. Nigel concluded you made a typo and actually have a P1102W, which may or may not be correct.

To be fair, google concluded that :D

But HP are generally excellent, and you can download all the drivers, instructions, etc.

But it's vitally important you folow the instructions, in the exact order they tell you - usually you have to install the drivers etc. before ever plugging the printer in. Always remember - RTFM.
 
been hacking at this code off and on but getting no where.
I ran the code in the help file but? trying to time 2 button presses.
Without the REPEAT UNTIL the display shows 0. With the REPEAT UNTIL loop both timers show same time.
this code is Swordfish
Code:
Device = 18F43k22
Clock = 8
//Config MCLRE = off
// some LCD options...
#option LCD_DATA = PORTD.4
#option LCD_RS = PORTD.2
#option LCD_EN = PORTD.3
// import LCD library...
Include "SetDigitalIO.bas"
Include "IntOSC.bas"
Include "LCD.bas"
Include "utils.bas"
'INCLUDE "Keypad16pullup.bas"
Include "Convert.bas"
Include "isrtimer.bas"
Include "EEPROM.bas"
Dim s As String
Dim mS As Word
Dim GO_1 As PORTC.0     //goes LOW when player presses switch
Dim GO_2 As PORTC.2     //goes LOW when player presses switch
Dim green As PORTE.0
Dim red_1 As PORTE.1
Dim red_2 As PORTE.3
Dim Shift_led As PORTA.0  //SHIFT LED
Dim blue1 As PORTA.1
Dim blue2 As PORTA.2
Dim yellow1 As PORTA.3
Dim yellow2 As PORTA.4
Dim YELLOW3 As PORTA.5
//Dim S_press As PORTC.0   //SHIFT BUTTON
Dim x As Byte        //USED FOR SHIFT POINTS
Dim RT_1 As LongWord   //REACTION TIME player 1
Dim RT_2 As LongWord   //REACTION TIME player 2
Dim ET_1 As LongWord   //elasped time player 1
Dim ET_2 As LongWord   //elasped time player 2
Dim Start_Time_1 As Word
Dim Start_Time_2 As Word
Dim End_Time_1 As Word
Dim End_Time_2 As Word
Dim timer1 As Word
Dim timer2 As Word


//Const

   //Timer1 = 0,

  // Timer2 = 1
  
  
Sub Int_Timer()
        Timer.Initialize(1)
        Timer.Items(0).interval=1  //ms
        Timer.Items(0).OnTimer=@OnTimer  //timer event handler
    //enable timers
        Timer.Items(0).enabled=true
        If GO_1=0 Then   //insert this into all the sub sequences but only last key in sequence
        Timer.Stop       //need to insert GETKEY
        End If
End Sub
 //RED LIGHT FOUL
 Sub Foul()
    If GO_1=0 And green = 0 Then
    red_1=1
    WriteAt(1,1,"FOUL" )
    DelayMS(3000)
        blue1=0 //led is off
        blue2=0
        yellow1=0
        yellow2=0
        YELLOW3=0
        green=0
        red_1=0
    Cls
EndIf
End Sub

// OnTimer event, flash LED...
Sub OnTimer()
    Inc(mS)
End Sub

Sub ET_time() //dispay results
        Timer.Stop //stop timer
        Cls
        s=DecToStr(timer1/1000)+"."+DecToStr((timer1 Mod 1000))
        WriteAt(1,1,"timer1    ")            //display players score
        WriteAt(2,1,"seconds   ",s,"     ")
        s=DecToStr(timer2/1000)+"."+DecToStr((timer2 Mod 1000))
        WriteAt(3,1,"timer2     ")            //display players score
        WriteAt(4,1,"seconds   ",s,"     ")
       // EE.Write(6,RT_1)
       // EE.Write(6,RT_1)
         DelayMS(5000)
         Cls
End Sub

      

Sub End_of_game()
    blue1=0 //led is off
    blue2=0
    yellow1=0
    yellow2=0
    YELLOW3=0
    green=0
    red_1=0
DelayMS(2000)
End Sub

 mS=0
 timer1=mS
 timer2=mS
Start_Time_1=mS
Start_Time_2=mS
End_Time_1=mS
End_Time_2=mS
Output(Shift_led)
Output (blue1)
Output(blue2)
Output(yellow1)
Output(yellow2)
Output(YELLOW3)
Output (green)
Output(red_1)
Input(GO_1)     //button press
//Input(S_press)//shift button
//GO_1 = 1    //input
blue1=0   //led
blue2=0   //led
green = 0 //led
mS=0      //timer set to zero

//initialize timer
Timer.Initialize(2)
Timer.Items(1).interval=1  //ms
Timer.Items(1).OnTimer=@OnTimer  //timer event handler
Timer.Items(2).interval=1  //ms
//enable timers
Timer.Items(0).enabled=true
Timer.Items(1).enabled=true
'mS = 0
'Timer.Start()
SetAllDigital

//START OF GAME
While True

DelayMS(1000)
blue1=1        //first stage light
        If GO_1=0 And green=0
        GoTo skipcode         //skipcode is a foul start
        DelayMS(1000)
        blue2=1
             If GO_1=0 And green=0
             GoTo skipcode
             DelayMS(1000)
                 yellow1=1
                 If GO_1=0 And green=0
                 GoTo skipcode
                 DelayMS(500)
                     yellow2=1
                     If GO_1=0 And green=0                   
                     GoTo skipcode
                     DelayMS(500)
                         YELLOW3=1
                         If GO_1=0 And green=0
                         GoTo skipcode
                             DelayMS(500)
                             If GO_1=0 And green = 0 //Then  //green = 0
                             GoTo skipcode
                             DelayMS(200)
    mS=0
    'Repeat       
    green=1        //start race
    timer1=0
    timer2=0
    
    Timer.Start
    ' Until
    if GO_1=0   Then //press of GO_x button
      
         timer1=mS
         EndIf
         if go_2=0 then
         timer2=mS
         endif
    
 End_Time_1=
 End_Time_2=mS
    ET_1=(End_Time_1-Start_Time_1)
    ET_2=(End_Time_2-Start_Time_2)
  
      

    ET_time()      //display time
  
    //mS=0
    
    skipcode:
     Foul()
     End_of_game()
                    
 Wend
 
You probably won't like or heed this advice, but I'll give it anyway.... What you're trying to do isn't difficult, but you've got a convoluted mishmash of code from various attempts at this that makes no sense whatsoever. Best bet is to throw it away and start fresh.

This isn't code. It's an outline of one approach to solve the problem.

First and foremost, do not use any delay statements. None. Zero.

Set up the timer to increment GameTime at 1mS intervals. Calling a variable mS is confusing to anybody trying to make sense of your code.

Create a boolean called ValidStart, and set it to false.

Define all your switches and LEDs.

Main Program loop:

Within a while/wend loop:

Start with an until loop
– Until start switch is pressed
–– ValidStart = false
–– GameTime = 0
–— LEDs off
–– timer off

When the start switch is pressed:
–– timer start
–– first LED on

If/then statement to check GameTime to turn on second LED if GameTime >= desired interval.

Another if/then statement to GameTime to turn on the 3rd LED at the appropriate GameTime and set ValidStart = true

Separate if/then statements to check if each player switch has been pushed. Check if ValidStart = true (foul if not) and then If so ElapsedTimeX = GameTime – the time the 3rd LED was activated.

Display ElapsedTimeX (X = player number)

Finish when all players have pressed their buttons or GameTime is greater than some amount.



Everything takes place in the main program loop in a very linear fashion. The only limitation to this very simple approach is that ties are indeterminate. It depends on where the program loop is at that particular instant. Reading this back, I would also create booleans for PlayerXDone. Set them to false initially and to true when their button is pressed. If PlayXDone = true, ignore addition button presses.


This is all I have to contribute. Extended travel awaits, and my biggest concern will be another piña colada.
When all players have pressed
 
Last edited:
been hacking at this code...
That's an understatement!

So, after I showed you how to use a single timer to time multiple things, you went back and tried (miserably) to use multiple timers again.

I know you can't just copy the code I provided, but you can't copy the code in the help file directly either.
At some point you're going to have to actually understand what some of this means.
 
I tried using your code as posted and it didn't work as planed.
Going to print out Jons suggestion and start from scratch
 
That's an understatement!

.....At some point you're going to have to actually understand what some of this means.

I tried using your code as posted and it didn't work as planed.
Going to print out Jons suggestion and start from scratch

Here's the problem. Tumbleweed has outlined what you need to do to get the timing done, and explained the process clearly.

I intentionally didn't write any code, but explained how to take Tumbleweed's times and get to what you're trying to do. Honestly, it wouldn't have taken much lower to write the code.

But now it's time you actually make the effort to understand what this all means. Nothing here is difficult, if you learn the concepts behind it instead of trying to program by your copy&paste technique. That approach is out of gas, as nobody is will to go through 20 pages of forums posts trying to explain why you can't assign a value to an input again.
 
Well making some progress, the display is showing the two elapsed times but GO_1 has to be pressed BEFORE the GO_2 press. Am using a WHILE WEND loop and Boolean (help file suggestion) but need to execute either button press order. Tried IF THEN.
Code:
While true

// start interrupt processing
mS = 0
Timer.Start()
green=1
// record starting time (current mS value)
StartTime = mS



while C0_isHigh  //portc.0  GO_1
      
EndTime_1=mS
wend
    while C2_isHigh  //portc.2  GO_2
      
    endtime_2=ms
   wend
 Timer.Stop //stop timer
green=0

ET_time()//(EndTime - StartTime)

Wend
 
Presumably, your switches have pull-up resistors?

Please answer: □ Yes □ No


If your switches have pull-up resistors, what value are they when not pressed?

Please answer: □ High


If the switch is not pressed, what will happen in the first while/wend loop?

Please think and answer in detail: ______________________


When the switch is pressed, what will happen in the first while/wend loop?

Please think and answer in detail: ______________________


Please process this information. Why will switch 2 never be read if switch 1 is not pressed?

Please think and answer in detail: ______________________


No further comments will be made unless and until these questions are fully answered. It's time to think and understand what's going on.
 
I have to apologize about my last post. I was frustrated at the time and just can't think about the logic my code does.
I realize taking a fresh look and realize my logic or code flow is wrong.
I in reality need two timers, one for each player. The loop I created is way out in left field.
Rethinking the code logic.
to answer Jons questions, yes switches have pullups and are high when not pressed.
The While Wend loops just go round and round until the second switch is pressed.
I need to track which player/ switch is pressed. Using Boolean logic seems like a good idea since it now displays two ET times but incorrectly.
 
Almost on the while/wend loops. It will be stuck in the first loop until S1 is pressed.

After that, it will be stuck in the second while/wend loop until S2 is pressed.

As I explained, test each switch with an if/then statement.

No, no, no, you do not need 2 timers. Geez. Scroll back and read the posts Tumbleweed and I have made.
 
I have a question...

You now have it displaying two times... one for player 1 and a second for player 2.

I take it you want to stop when either one of the players presses their button.
If that's the case, when player 1 presses his button and everything stops, what do you want the timer for player 2 to show?
He never pressed his button, so he shouldn't have a time.

Don't you just want to show who was first and what their time was?
 
I tried an IF THEN statement and get 0 times. With the while when statement it displays two different times. WHY you ask? the ET is started when the green led is on and the time displayed is ET from green on to second button press.
Player 1 presses his/ her button and the display indicates the ET between the green led ON and time of button press.
Player 2 has same scenario but likely different ET display.
Getting the notion that I need two UNTIL loops?
 
Player 1 presses his/ her button and the display indicates the ET between the green led ON and time of button press.
Player 2 has same scenario but likely different ET display.

So the two players don't really play against each other... it's more like there are two separate games and either one or two players can play.
Player 1 (the GO_1 button) would always start a new game, and if you don't have a player 2 then the GO_2 button just ends up being ignored since it was never pressed?
 
The logic is weak in this one. Explaining why something cannot possibly work isn't worth bits it takes to show it.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top