Shop OBEX P1 Docs P2 Docs Learn Events
Edge detection — Parallax Forums

Edge detection

RsadeikaRsadeika Posts: 3,838
edited 2008-10-10 15:59 in General Discussion
I know that some of the pins can be set up in a way that it detects a change in the Voltage level, and then it does some specific code. I am using an SX52 protoboard and I want to assign one pin to detect a voltage level change, of course I want this to be done in SX/B.

In my project, the robot, when it goes into a charging mode, "... this pin is high(5V)". I will have that pin connected to a pin on the SX52 protoboard, so when the protoboard detects the pin at 5V, it will know that it is made the connection between the robot charge surface, and the charger. At this time I want to have the SX52 protoboard wait until it detects the voltage of 0, which means it has been charged up, now I will have some code to make it do something.

I guess the questions are, 1) Can this be done in SX/B? Since I did not see any commands that I recognized to achieve this. 2) Can this be done without using an isr? I am using serin/serout extensively, so I do not want to mess things up in area. As a side note, the SX52 protoboard is a slave to the Prop protoboard; I have them connected up at 230400 BAUD with no problems what so ever. I may, at this time, try to boost up the BAUD rate, to see at what point this all starts to fall apart.

Any advice on this will be appreciated.

Thanks

Ray

Comments

  • BeanBean Posts: 8,129
    edited 2008-10-10 14:10
    Ray,
    Firstly, why can't you just check the pin state with "IF pinx = 1 THEN" ???

    Do you really NEED an interrupt ?

    You can use the WKPND_B register to see if an edge occured on one of the RB pins. This register gets set when the pin changes state. Even if the state change is just a very fast pulse (that you would miss if you just polled the pin state).

    More details please...

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    "It is our choices, Harry, that show what we truly are, far more than our abilities."·Dumbledore from Harry Potter

    www.iElectronicDesigns.com

    ·
  • RsadeikaRsadeika Posts: 3,838
    edited 2008-10-10 14:41
    Thanks Bean, that concept, "IF pinx = 1 THEN", completely eluded me. I did not think that the solution would be that simple, and straight forward. Now, does the pin have to be designated as 'input', or it does not make a difference? I guess this is not going to be as complicated as I thought it would be.

    Thanks

    Ray
  • JonnyMacJonnyMac Posts: 9,214
    edited 2008-10-10 15:59
    If your pin is not an input you'll be reading the state of the output register. By default, pins are made inputs on start-up, but there's no harm in designating INPUT in the PIN directive (this becomes a form of documentation). Make sure that you pull the pin to the "off" level so that a disconnected or floating output on the other side does not create a false positive.
Sign In or Register to comment.