Shop OBEX P1 Docs P2 Docs Learn Events
PBASIC help - Page 2 — Parallax Forums

PBASIC help

2»

Comments

  • TechnikFIPTechnikFIP Posts: 9
    edited 2012-02-01 11:07
    TechnickFip.

    I need the distance between the 2 beams in mm (the distance betwwen the first beam and the seconds beam). Both beam must be parallael to each other.

    After you tell me this, I will show you how to calculate the speed.

    Paul

    the distance in MM is 100 mm
  • Paul RomskyPaul Romsky Posts: 66
    edited 2012-02-01 18:50
    Finn,

    I actually ran the code on a BS1 today (I forgot to put the # in front of the Count variable in the DEBUG stament.

    Anyway, as you may have seen, if something moves very fast through the beams, the count will be zero. This is because the BS1 is very slow. But I have an idea.... You will be able to use the PULSIN command if you add some simple circuitry which I will draw up for you. With PULSIN you will get bigger Counts for fast speeds. I suggested the code I gave you to keep your cost down. How fast do you expect an object to travel through the beams? If it is slow the way we have it now will work, but if you start seeing counts less than 3, then you may need to add some more circuits (or go to a BS2). Let me draw up the circuit.

    Paul
  • Paul RomskyPaul Romsky Posts: 66
    edited 2012-02-01 19:45
    Finn,

    Let's assume that your objects don't move too fast and we don't need to use PULSIN and some external hardware. I will draw that circuit up tomorrow (just in case you need it).

    Attached is a code update. Read the comments and look at the added code. You should now be able to calculate speed from the Counter value. Don't do the math in the BS1 just yet, do it on a calulator. Remember... the PStamps CAN NOT do floating point math - they CAN ONLY do integer math, so we have some tricks we have to play with code to work with fractional numbers (we will move on to this after you tell me how long it takes 1 count in seconds - or in ms to be more precise).

    Paul
  • TechnikFIPTechnikFIP Posts: 9
    edited 2012-02-02 08:36
    Finn,

    (we will move on to this after you tell me how long it takes 1 count in seconds - or in ms to be more precise).

    Hello Paul,

    We don't want that the object will be fast. I'll be very glad to see these circuits of you.
    Well I don't understand what you want to know with this (look on top).

    Finn
  • Paul RomskyPaul Romsky Posts: 66
    edited 2012-02-02 16:46
    Finn,

    Ok, since you don't expect fast moving objects, the method of using a counter (as it is now) will work. I didn't draw up the circuit (for external logic) yet, but since you don't need it, there is no need for me to send it to you.

    To be sure you are doing this correctly, I wanted YOU to tell me how long 1 count takes in seconds. I gave you very clear instructions in the code. It was up to you to figure out this very important constant. Because you are new to PStamps, you should make this calculation on paper because the PStamps can only perfrom integer math. To teach you how to do floating point math using an integer math Arithmetic Logic Unit (ALU) - which is inside the PStamp - is an invloved process. So I wanted to see if you can do the math to figure out the speed of the object based on the fairly detailed information that I have given you.

    Most people in this forum will not send you code, let alone full working examples as I have done. My role here is to teach you, not to do your work for you.

    Since you have failed to take the initiative and to come up with a solution on your own, I can no longer help you.

    Paul
Sign In or Register to comment.