Shop OBEX P1 Docs P2 Docs Learn Events
timer function — Parallax Forums

timer function

littlerichlittlerich Posts: 27
edited 2009-05-18 02:44 in BASIC Stamp
I am trying again a project that was started a long time ago and as a newbie still struggling a bit.

Using a BS2P40

I have a proximity sensor hooked up to an input.
The aim is to count the time between pulses (rising edges say) and then calculate rpm.

The way I see it I can either count on a unit of time basis however the basic stamp doesn't really cater for this.

Or

Use a counter and maybe evaluate the number of counts in a given period of time so the count number can then be converted to time and therefore rpm.

This is only intended to be a small part of the program so the program must continue to execute while calculating this time.

When it sees a pulse I want to start again.

The overall rpm could be anywhere from 5 to 750 rpm.

In the past I have tried the button command somewhat unsucessfully as it appears the micro is dedicated to this cause until it gets to move on.

I also need a strategy to get rid of bounce. I do have a transmitter also connected and when watching this data in a remote terminal screen it tends to go crazy with keybounce.

Any thoughts appreciated.

·

Comments

  • Clive WakehamClive Wakeham Posts: 152
    edited 2009-05-17 11:57
    I have a proximity sensor hooked up to an input.
    The aim is to count the time between pulses (rising edges say) and then calculate rpm.
    ·
    The way I see it I can either count on a unit of time basis however the basic stamp doesn't really cater for this.

    I don't understand how you have a proximity sensor and you want to calculate rpm (revolutions per minute).

    In the past I have tried the button command somewhat unsucessfully as it appears the micro is dedicated to this cause until it gets to move on.

    The Basic Stamp family doesn't have multi-taking capabilities, really only the Propellor chip does.

    I also need a strategy to get rid of bounce.

    If you don't want/can't use the Button command, the only other way (without additional components) would be to put the whole thing in a loop.

    Thats how I had to do it when I needed my robot to continue driving forward whilst the ultrasonic sensor turned side to side taking readings. The loop was very tight so there was no jerking in the motion of the robot. It took me a week to finally get it to the point I was happy with the program (eight versions of the program) and the limitations of the Basic Stamp IIp.
  • littlerichlittlerich Posts: 27
    edited 2009-05-17 12:04
    The proximity sensor detects metal objects.
    I have attached a bolt to the shaft of my rotating object.
    The prox will detect the bolt head going past.

    So I need to count loops or time between pulses and then determine rpm.

    Hopefully while executing other portions of code.

    Have looked at the Propellor and can see it would be great.
    I am unfortunately to new to jump into this chip. It seems quite a jump to this platform.
  • stamptrolstamptrol Posts: 1,731
    edited 2009-05-17 13:24
    Have a look at the PULSIN statement (in online help file). It will give you the time between pulse and you can calculate rpm from there. Or, use COUNT for a short sampling period and covert to rpm.

    As was pointed out, Stamps (and most other small processors) are single task devices. So, what you can do is have the Stamp get the rpm, go do something else, come back and check the rpm, go do something else, etc. This way more than one task can be accomplished, not at the same time, but in quck succession.

    Cheers,

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tom Sisk

    http://www.siskconsult.com
    ·
  • Clive WakehamClive Wakeham Posts: 152
    edited 2009-05-18 02:44
    Also have a look at the poll commands.

    You could set it up so it runs a subroutine (in a different memory slot) every time the pin value changes.
Sign In or Register to comment.