Shop OBEX P1 Docs P2 Docs Learn Events
Help using POLLIN command or alternatives — Parallax Forums

Help using POLLIN command or alternatives

Leo.KLeo.K Posts: 21
edited 2008-03-23 01:45 in BASIC Stamp
Hi there,

I'm having difficulty using the POLLIN command as it doesnt seem to be working. What I'd actually like it to do, when Pin 3·is driven·low is, to finish executing·the contents of EEProm 3 (Writing to USB datalogger) then to run EEProm 4. Is there a method to do this as I dont need it to check regularly for pin low. Just once per iteration of EEprom 3 would be fine. Can somebody help please? I'd like·the whole program·to execute as quickly as possible, so would rather not be polling between instructions if possible.


This is what I have put at the top of EEProm 3 as it is during EEProm 3 execution that the·pin 3 will be driven low

Setup:
· POLLIN 3, 0
· POLLRUN 4
· POLLMODE 0

· Some code here

· Run 3

I then drive the pin low by connecting it to earth but it doesnt seem to work. I also tried setting it high first during EEProm 1, using HIGH 3. If I do have to use POLLIN I'd at least like it to finish executing EEProm 3 first.

Thanks very much in advance for any help/advice people can offer.

Leo




·

Comments

  • Tracy AllenTracy Allen Posts: 6,667
    edited 2008-03-22 17:19
    POLLMODE 0 is not an active mode. It basically means "polling off".

    To make it work you have to choose one of the POLLMODEs that activates the RUN when p3 goes low.

    Moreover, if you need to finish execution in slot 3 (a good idea when writing to the USB datalogger), then the sudden branch to slot 4 is not really what you want.

    Try
    POLLIN 3,0
    POLLMODE 10

    then when finished with slot 3, then check the polling status bits at location 128 in scratchpad. You could alternatively activate the POLLRUN mode at that time. At some point do a POLLMODE 0 to reset the latches. It is important to realize that the pulse on p3 will still have to have a certain duration in order for the Stamp to catch it. There are workarounds that have to do with stretching the pulse with a capacitor.

    I have a little writeup on POLLing at,
    www.emesystems.com/BS2poll.htm.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • Leo.KLeo.K Posts: 21
    edited 2008-03-22 20:19
    Wow, thanks tracey! That's great I will give it a go

    Leo

    EDIT: Hi Tracey,

    I tried what you said and it seems to work if I put

    POLLIN 3, 0
    POLLRUN 4
    POLLMODE 10

    But as you say this doesnt finish the slot 3 before moving onto slot 4.

    I tried to put

    POLLIN 3, 0
    POLLMODE 10

    - My Code -

    POLLRUN 4

    But it doesnt seem to work. I used

    GET 128, index
    DEBUG DEC index

    Which outputs an "8".·I thought I was looking for a 1 or 3? The value of 128 is 0 before I press the switch.

    I also put POLLMODE 0 in after POLLRUN 4 which does reset 128 to 0 but doesnt help in any other way. Does this "POLLMODE 0" need to be in my program slot 3 or could I put it at the start of slot 4? I'm just trying to keep the number of instructions to a minimum.

    Thanks very much for you help on this and my other post.

    Leo

    Post Edited (Leo.K) : 3/22/2008 8:29:54 PM GMT
  • Leo.KLeo.K Posts: 21
    edited 2008-03-22 20:45
    Hi Tracey,

    I think I have cracked it, please could you tell me if this is the most suitable and quickest way to do this?

    I wrote

    HIGH 3

    POLLIN 3, 0
    POLLMODE 10

    - My Code -

    POLLRUN 4
    POLLMODE 3

    Then the first command in program slot 4 is

    POLLMODE 0

    Thank you very much

    Leo
  • Tracy AllenTracy Allen Posts: 6,667
    edited 2008-03-23 01:45
    That last approach looks good to me. I don't use POLLRUN very often, so you will have to try it and see!

    When you look at the polling status location,
    GET 128,index
    you will see an 8 there in the event that pin p3 goes to the active state that you defined by the POLLIN 3,0.
    That is %00001000 = 8 where each bit corresponds to one Stamp pin. SPram locations 128 to 131 have one bit for each of the 32 BS2p40 input pins. The POLLMODE 10 instruction tells the Stamp to latch the bit, as opposed to the POLLMODE 2, which does not latch it. That is, once p3 goes low, bit 3 in location 128 will go high and stay there until it is reset. You can either do the POLLRUN 4 : POLLMODE 3, or you can examine that bit as follows:

    GET 128,index
    IF index.bit3=1 THEN RUN 4

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
Sign In or Register to comment.