comparing input signals in assembly
latofte
Posts: 9
Howdy again, I hit another small roadblock
I am trying to make my own design to learn flags/input voltage stuff.
So far I have it set to have only pins 14 and 15 as inputs and pin 16 is connected to an led
Pin 14 is connected directly to 3.3v and pin 15 is connected to a switch which is also connected to 3.3v
However even with the button pushed it thinks both pins are not equal
I am unsure if simply equal voltage is indeed all you need to do to compare/test (tried both) pins.
once I figure out the neat/clean way to put up code I will have it up
(also working on learning functionality before I start to learn to clean up my code >.> sorry)
I am trying to make my own design to learn flags/input voltage stuff.
So far I have it set to have only pins 14 and 15 as inputs and pin 16 is connected to an led
Pin 14 is connected directly to 3.3v and pin 15 is connected to a switch which is also connected to 3.3v
However even with the button pushed it thinks both pins are not equal
I am unsure if simply equal voltage is indeed all you need to do to compare/test (tried both) pins.
once I figure out the neat/clean way to put up code I will have it up
(also working on learning functionality before I start to learn to clean up my code >.> sorry)
PUB Main cognew(@Button, 0) DAT ORG 0 'Begin at Cog RAM addr 0 Button mov dira, output 'sets only 14 and 15 to input mov Time1, cnt 'Calculate delay time add Time1, #$100'Set initial delay here :waiting waitcnt Time1, Delay1 'Wait mov outa, zero waitcnt Time1, Delay2 'Wait test Ina, pushed If_E jmp #:LED If_NE jmp #:LED2 {If both pins are high it should jump to faster blinking LED} :LED {blink faster} or outa, Pin16 waitcnt Time1, Delay1 xor outa, Pin16 waitcnt Time1, Delay1 xor outa, Pin16 waitcnt Time1, Delay1 xor outa, Pin16 waitcnt Time1, Delay1 xor outa, Pin16 waitcnt Time1, Delay1 xor outa, Pin16 waitcnt Time1, Delay1 jmp #:waiting :LED2 {slow blink} or outa, Pin16 waitcnt Time1, Delay2 xor outa, Pin16 waitcnt Time1, Delay2 xor outa, Pin16 waitcnt Time1, Delay2 jmp #:waiting output long %11111111_11111111_00111111_11111111 Zero long %00000000_00000000_00000000_00000000 Pushed long %00000000_00000000_11000000_00000000 Pin16 long %00000000_00000001_00000000_00000000 Delay1 long 100_000 Delay2 long 10_000_000 Time1 res 1 'System Counter Workspac
Comments
I also added Bits res 1 at the end and changed the code to
....
Mov Bits, Ina
And Bits, Pushed
Cmp Bits, Pushed
IF.....
But still not accepting that the two are equal
but 01 and 10 and 11 will both produce Z=0
1st you need a pull-down resistor as stray electricity make keep the input in a unkown state
as it's pretty much is a antenna if not connected to 3v or ground.
And your code can be simplified alot, think statemachine.
1) ina must be the source register, otherwise you read the shadow ram
2) you nead to specify the flags that you will have affected with wc, wz
3) TEST does an AND of the INA and the Mask in "pushed". pushed masks both pins, so you can only detect if both pins are low or not. But Pin14 is always high so you will never get the zero flag set:
If you want compare two input pins, the best way is to read one pin into the Carry flag and the second pin into the Zero flag, then you can use the IF_C_EQ_Z and IF_C_NE_Z conditions: Be aware the the Zero flag is set if the pin is low and vice versa,but the Carry flag is set if the pin is high.
Andy
I was trying to figure out how to use those flags, now hopefully I can get a few more practice problems under my belt before I come begging you guys again
Or fast blink if both buttons are the same 0=0 or 1=1 ?
Not forgetting wz or wc with the opcode test, is a must.
Inverting the switches, by using pull-up resistor and switch to ground.
and you can get away with the single: test mask, ina wz
as z=1 only if all pins in mask=0, if you want that both switches need to be pushed.
Nice solution!
I need to be more careful with adjectives like "best", if there is a possibility that you read the thread
Andy