Whats going on here??

radiogareth

Senior Member
This is some snooker scoreboard code that simulates fine.

However, in hardware the b0 register will not count up past 1, UNLESS the buttion is held down.
The similar colour count section works fine using b1. What are we missing?? - both teacher and pupil are involved here!!

Thanks

Gareth
Code:
'Section 0
'if black goes high, make all outputs high
'if red goes high it will add 1 to the red value
'    Check the red value.
'    if the red value = 15 then send red output high and goto section 1
'    if red value is not 15 then go to step 0

'Section 1
'if black goes high, make all outputs high
'if colour input goes high add 1 to colour value
'    if colour value = 5
'    colour output goes high and goto section 2

'Section 2
'if black goes high, make all outputs high



main:
    symbol red = pinb.0
    symbol color = pinb.1
    symbol black = pinb.2
    symbol newgame = pinb.3
    let dirsB = %11110000
    let dirsC = %10000011
    let pin7 = 0
    let pin0 = 0
    let pin1 = 0
    goto seered:

seered:
    if newgame = 1 then
    goto newgamepress
    else if black = 1 then
    goto blackpress
    else if red = 1 then
    goto redpress
    else
    goto seered
    end if

seecolor:
    if newgame = 1 then
    goto newgamepress
    else if black = 1 then
    goto blackpress
    else if color = 1 then
    goto colorpress
    else
    goto seecolor
    end if

seeblack:
    if newgame = 1 then
    goto newgamepress
    else if black = 1 then
    goto blackpress
    else
    goto seeblack
    end if

redpress:
    pause 700
    b0 = b0+1
    debug
    if b0 = 15 then
    let pin7 = 1
    goto seecolor
    else
    goto seered
    end if

colorpress:
    pause 700
    b1 = b1+1
    debug
    if b1 = 5 then
    let pin0 = 1
    goto seeblack
    else
    goto seecolor
    end if

blackpress:
    pause 700
    let pin7 = 1
    let pin0 = 1
    let pin1 = 1
    goto seered

newgamepress:
    pause 700
    b0 = 0
    b1 = 0
    debug
    let pin7 = 0
    let pin0 = 0
    let pin1 = 0
    goto seered
 
Last edited by a moderator:

nick12ab

Senior Member
In the simulator b0 only counts up when the input B.0 is high. That is what you programmed it to do.

The buttons in the simulator are toggle buttons so if you press it once it stays on then turns off on the second press. The buttons in real life are push to make switches so they only stay on when held down and therefore the input pin is only high when the button is held down.
 

radiogareth

Senior Member
OK, sorry no suitable schematic at this point....
We realize that the simulator button toggles, a quick double click and the simulation works as expected.

The hardware works as expected too, but B0 will not increment past 1 UNLESS you literally hold the button down as the code runs round. Switches are de-bounced in hardware too.
B1 does increment as expected, per button press. The hardware is the same on both, you can swap the button outputs around and the fault follows ie B0 does not increment past 1. It must be something simple, but I/we can't see it.

BTW, thanks for putting the code tags on the listing, could we have them in with the Smilies perhaps??

Gareth
 

Technical

Technical Support
Staff member
Do you really have a colon here?


goto seered:

You can remove that line entirely.
 
Top