basic stamp as a D flip flop
tedroberson
Posts: 8
Hi everyone.I'm new at programing,need all the help I can get.
Thanks.
Can the bs2 be configered as a JK or D f/f?
Any info will be helpful.
Thanks.
Can the bs2 be configered as a JK or D f/f?
Any info will be helpful.
Comments
It is possible to simulate state machines in firmware on the BASIC Stamp, but their response will be slow, on the order of several milliseconds instead of less than 1 microsecond. Emphasis, it has to be done with firmware code, and is not like a PGA where you are configuring hardware gates.
D flip-flops in general have 6 i/o pins: D, Clock, Set, Reset, Q and Q\, so you might want to simulate the action of all those pins, or just a subset. A J-K flip flop only has 5 i/o pins, but the internal logic is more complicated, because levels on the J-K inputs simulate a D, T or SR flip-flop.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
I've designed a·switching circuit that controls three relays,·using all discrete components.
I have a working prototype. I thought that by·using a microcontroller I could cut cost and
components.
At power up,my design defaults to out put 1, at this point I can randomely
push any switch (n/o mom.) and control any out put.
I don't have that flexibality with basis stamp,I can only· move· from 1-3 foward or reversed.
Due to the loops, I'm always locked in a sequential direction foward or backwards.
There must be some way I can overcome this.
Any other comments will be greatly appreciated.
Many thanks for your speedy reply.
programs that I've configured,so far its the closest
to what I'm looking for.
At power up, red led is on.
In3 turns off the red led and green led is on.
In4 turns off the green led and the yellow led is on.
In6 resets to routine1.At this time if In4 is pushed,red led is off, green is on. From this point I have to start all over.
Normal seq. is : Routine1 is: Start up default 1,2,reset to 1,or in4 to go to 2. Then seq. starts over again.
I would like to control all three out puts in any random order.
That I choose. I can do this with my discrete circuit usind D/FFs.
' {$STAMP BS2} 'AMP SPK VER.2 ' Power up.Red LED on.
' {$PBASIC 2.5}
'
DEBUG ? IN3' SW1
DEBUG ? IN4' SW2
DEBUG ? IN6 'SW3
'do
DEBUG HOME
HIGH 15 'red on
DO
routine1:
LOOP UNTIL IN3 = 1
LOW 15
LOW 13
HIGH 14 'green on
DO
LOOP UNTIL IN4 = 1
LOW 14
LOW 15
HIGH 13 'yellow
DO
LOOP UNTIL IN6 = 1
LOW 13
GOTO reset
reset:
HIGH 15
DO
LOOP UNTIL IN6 = 1
LOW 15
LOW 13
HIGH 14
DO
LOOP UNTIL IN4 = 1
LOW 14
HIGH 15
GOTO routine1
You can also test to see if a switch goes from on to off. Basically you've saved the state of the switches when any of them changes, then you can test for various combinations. You can test for one switch going from off to on while another switch is on.
Does the following program do something like what you want? You have to define these problems very precisely, what do you want to happen when!!
This is based on changes, that is, if you hold down the red button and then press the yellow button, the red will go off and yellow will come on. The program would be simpler if yo used pins in sequence, for example, pins p1,p2,p3 to control leds on pins p13,p14,p15.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
Post Edited (Tracy Allen) : 2/26/2010 3:47:45 PM GMT
All info received has been very helpful.
I'm new at this programing game so I'm as dumb as I seem.
( LOL)Most forums, you ask dumb questions,you get dumb answers.
Not so with you guys. Thanks
New is not dumb! You got your circuit working, so with a littel more persistence you will be able to do that and more with the Stamp!
I added one important line to my trial program. A dumb mistake on my part -- never too old to make dumb mistakes!
DIRD = %1110
That makes outputs out of the led pins. Otherwise the Stamp default is for them to be inputs. Commands like HIGH 15 turn pin into an output and make it high. But the OUTD command does not automatically make the pins outputs. Note that state machine logic on microcomputers most often will involve the bitwise logic operators, like ^ (stampese for bitwise XOR) and & (bitwise AND).
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
And good advice you gave me was a great help.
This is a great forums for beganners.
I think the code that you cover here is close to what I need for a current application.
What I need are: a set of 10 momentary buttons with an accompanying set of 10 LED's (namely they are illuminated momentary pushbuttons)
I need for each of them to latch; that is, for the corresponding output pin to go high and remain high until any other button is depressed, and for the latch to then shift to the next (random) button to be depressed.
Put very simply: There are ten buttons, which when pressed, light up and stay lit up until a subsequent button is pressed.
This circuit would be used to control an adjacent system with it's own set of digital inputs and would serve purely as indicator of the last button to have been pressed.
From what I can make out, the example code that Tracy Allen has provided above seems to closely represent what I need however I am a little unclear as to how the Hex variables: DIRD = %1110 OUTD = %1000 work?
Any further guidance would be hugely appreciated.
Thanks again.
Dan
http://www.parallax.com/tabid/440/Default.aspx
DJ