Edge Trigger

Rickharris

Senior Member
As a teacher can I point out something here - You have to do at least some of the work yourself. You should also credit ALL work supplied by someone else.

I strongly suggest at this point you say thanks to all who took the time to support you and get to work making it happen.
 

otm

Member
I have already done that... one step ahead.. (I'm not the kind that doesn't appreciate the work of others, Unlike some of the people I know in my school).

Now to complete the learning process, can you please explain (in detail) how checkifshape removed works and what it does so I can explain in my project how it works and I can then mention like I have at the top of the program, all the great help you guys have given me.


Thankyou so Very much,
You all will all have a note at the head and foot of my code.

Again Thankyou,

Owen

Edited by - otm on 04/02/2007 14:51:49
 

atharvai

Senior Member
I can give u a simple hardware solution. From ur 2nd post it appears that when the shape is placed inside ur input goes from 1 to 0. so U r looking at a falling edge trigger. place a capacitor and a resistor in series with the resistor connected to +5V and ur capacitor to ur input(switch) then connect ur PIC input pin between the resistor and the capacitor. This will produce a pulse (0-->1) everytime there is a edge from ur switched (slots)
 

BeanieBots

Moderator
That will indeed produce a pulse. A very short pulse unless the capacitor is very large. This would then need to be diode OR'd for all the inputs to generate a pulse on the interrupt pin.
Also, once the trigger has taken place, there will be no signal left to indicate that the shape is still there. (I think that is also a requirement).
 

atharvai

Senior Member
OK but can u not add rising edge trigger on another input... this will allow him to detect both if the shape in in the slot or being removed....

the value of capacitor can be chosen to ur needs but i do not believe u need a diode. the input directly to PIC from edge trigger detector should be fine... I have used this before...
 

BeanieBots

Moderator
The diode OR is because interrupts can only work off ONE input and ONE state transition. So, no, you could not just add the other edge trigger.
If there is more than one input, they must be OR'd. The easiest way to do that is with diodes (but, obviously only for one edge type).
As for time constants, what sort of values were you thinking of?
Maybe 10k/100nF ~ 1mS.
Without interrupts, the code would need to poll at least every 1mS. Not impossible, but would be tricky at ~ 250uS per command.

Sure, the differential RC you describe will present 'edge' trigger signal, but there is not much that the PICAXE could do with it.
 

otm

Member
thankyou for the ideas, I did look at using an electronical edge trigger, however, my teacher said that they are diffucult to work with so I was swayed off of it (and also I'd already designed, etched and soldered the board before starting the topic hence why I insisted on using an input from 1 to 0 because i was going to use an opto switch, which we could never get to work. so we changed it to magnet switches because no board alterations were needed).

Thankyou for your input in the topic, thankyou.

Owen
 

SD2100

New Member
Here's an attempted explanation of the CheckIfShapeRemoved sub. If I screw it up someone will correct me.

The Flags variable is made up of one byte, within this byte there are 8 bits.
Each bit has a value, if all bits are set to 0 then Flags would equal 0, if all bit are set to 1 Flags would equal 255. The values for each bit are:
bit0 - 1
bit1 - 2
bit3 - 4
bit4 - 8
bit5 - 16
bit6 - 32
bit7 - 64
bit8 - 128

We are using 4 of these bits to enable (send message) or disable (don't send message) to the LCD.
Each of the 4 bits used is assigned to a shape
<code><pre><font size=2 face='Courier'>
Triangle - bit0 (1)
Circle - bit1 (2)
Square - bit2 (4)
Rectangle - bit5 (32)
</font></pre></code>
At the start of the progam all bits we are using (0,1,2,5) are set to 1 via the Flags variable (39), as the program cycles and each shape is inserted the bit for that shape is cleared so the value of the Flags variable decreases, with all shapes in the holes Flags = 0, all out Flags = 39.
When the CheckIfShapeRemoved sub is called the variable PinState is set to equal the state of the input pins, the mask (%0100111) is used to filter out unwanted input pins by logially ANDing all input pins with the mask eg:
the line &quot;PinState = pins &amp; %00100111&quot; gets the state of inputs we want and filters out the unwanted inputs, see below
<code><pre><font size=2 face='Courier'>
Bit/pin No 76543210
-------------------
pins = 10000110 &lt;- all input pins
mask = 00100111 &lt;- we only want pins 0,1,2,5 so mask out the others
-------------------
PinState= xx0xx110 &lt;- result of pins with unwanted inputs filtered out.
</font></pre></code>
The bits in PinState that are shown as &quot;x&quot; will always be 0 as these have been filtered out by the mask.

You can see when pins is ANDed with the mask and a 1 in pins aligns with a 1 in the mask that a 1 is put into PinState, so because PinState = 00000110 this tells us that
Pin0 = 0 - Triangle in the hole
Pin1 = 1 - nothing in hole (Circle)
Pin2 = 1 - nothing in hole (Square)
Pin5 = 0 - Rectangle in the hole

With a triangle and rectangle in the hole Flags will equal 6 as the starting value of Flags was 39, then a triangle was put in, this subtracted 1 from Flags by clearing bit0 then a rectangle was put in, this cleared bit5 of Flags so 32 was subtracted from Flags so 39 - 32 - 1 = 6.

The line &quot;if PinState &gt; flags then&quot; checks if any shapes have been removed. with the example above Flags = 6 and PinState = 6 so 2 shapes are in and nothing has been removed. if a shape is removed the PinState value will increase as the input pin goes high which adds to the PinState value, when PinState is greater than Flags then the line &quot;flags = PinState&quot; is executed, what this does is set the bits in Flags the same as the inputs, in the example above if the rectangle was removed then PinState will change from 00000110 to 00100110 as pin5 has gone high so now Flags = 00100110 which means bit5 is now 1. What this has done isre-enabled the rectangle so next time it's put in the condition&quot;elseif pin5 = 0 and bit5 = 1 then&quot; will be true so the message will be sent to the LCD. This goes on and on setting and clearing the bits in the Flags variable as shapes are put in and pulled out.

Hope that wasn't too painful. :)


Edited by - Phil75 on 06/02/2007 06:36:38
 

otm

Member
Thank has made a lot of sense, a second detailed readthrough later on I will probably have it down.

Thankyou soo very much for you help Phil, and everyone who posted a respones on the forum. Thankyou...

Owen
 
Top