Shop OBEX P1 Docs P2 Docs Learn Events
Correction in a few spin commands for input/output needed please — Parallax Forums

Correction in a few spin commands for input/output needed please

Dan EDan E Posts: 61
edited 2011-01-21 09:48 in Propeller 1
Hi,

I modified some langauge in a debounce button object that was originally written by another forum member to help me rotate a servo clockwise and counterclockwise by pressing one of two buttons, one for each direction.

I now am trying to use two other buttons to turn on and off a piezo buzzer. I commented the code that I added with descriptions of what I was trying to accomplish. I ran the code and no buzzer resulted. I am still very new to the Spin langauge, and the few lines I wrote seemed logical, but it is not correct.

I have an ultrasonic rangefinder that has its PWM output going to the propeller. The code I added says for a piezo buzzer to sound whenever the PWM is at a high state. Since the period of the PWM will change with the distance of the object detected by the rangefinder, I assumed the pitch of the buzzer would change as a result. I added a delay after the buzzer first sounds, then it is to shut off, wait, then repeat. This is so that there will be a noticeable beep, so that it would be easier to determine a change in pitch.

The purpose of this is so that a group of blind students can have audible clues where to aim a bowling ramp, so that they can locate the closest pins.

The first debounce button turns on the buzzer, below is the code I wrote for this action:
buzzer on.jpg


The second debounce button is to silence the buzzer, below is the command I wrote for that:
buzzer off.PNG


From what I read in the manual, these commands seem to be accurate, but possibly they are meant for a different type of statement.

I attached the full object so people can see the context of how I would like to use these commands.

Aim guide - Archive [Date 2011.01.20 Time 01.00].zip

If the logic of having the varying PWM input to the propeller change the pitch of the piezo buzzer isn't realistic, then I would truly appreciate some suggestions as to how I could accomplish this. Also if someone could point out the error in the few commands I contributed, because the program compiled so I am unable to determine where the error is, and I would like to learn so that I don't do it again.

Thanks,
Dan

Comments

  • Dan EDan E Posts: 61
    edited 2011-01-20 14:45
    Thanks, that makes sense, I forgot about that command.

    I still wasn't able to get to buzzer get the buzzer to operate, but I did some debugging, and I'm pretty sure I know why, and this time i'm sure its not the code.

    The PWM input to the propeller from my ultrasonic rangefinder reads as is:

    120mV when I hold my hand up to a foot away from its sensor

    370mV high when I emove my hande and the signal bounces off the ceiling, which is about 6ft above the table I tested on.

    410mV when I pointed the sensor out the window, which I think it picked up some trees about 8 feet away, so I couldn't get a realll long distance observed.

    The typical distance of the final application will be from 10 to 20 feet. I also measured 0 volts coming out the pin that is to power my piezo buzzer.

    I'm pretty sure this tells me that there is not enough voltage going to the input pin to switch the state to high. I held the debounce button in, and also just quickly pressed it to confirm that the result was still no voltage being outputed to the buzzer.

    I wrote a new program that just tests what I am trying to do, minus the debounce buttons, so that I can eliminate sources of possible error. Same deal.

    Buzzer and Rangefinder Test - Archive [Date 2011.01.20 Time 17.39].zip

    To further debug, I attached 3.3v directly to the input pin, and the buzzer sounded.

    What I can guess from this is that more voltage is required to be detected as an input, than what is coming from the PWM output?

    What is the minimum amount of voltage needed to switch an input from a low state to a high state? Also, what is the maximum, so i don't burnout the chip inadvertantly?

    I hooked up different voltages to the buzzer, and it beeped with different amplitudes rather than changing the pitch as I had hoped.

    Anyone have any suggestions on how to change the pitch to correspond with PWM input?

    Thanks,
    Dan
  • Dan EDan E Posts: 61
    edited 2011-01-21 08:08
    Thanks, I tested your sample code and it sounded pretty cool, I added 'repeat' at the beginning to get the constant on/off beeping I was looking for. I also varied the 'waitcnt', and the response was exactly what I was looking for. Changing the frequency of the buzzer like you did, makes it sound less irritating, which is important because the users of my school project may have other disabilities in addition to being blind, so the noise shouldn't be startling.

    Basically with the combination of the ultrasonic rangefinder and the piezo buzzer, I am trying to make a proximity detector.

    So it seems in order to make this happen, I need to have the 'waitcnt' vary as the PWM input varies.

    The voltage from the rangefinder will most likely be varying from about 200mV to 500mV so I would have to write an equation to scale those values to a set of increments that made sense.

    Is it possible to take the magnitude of the PWM input and have it be the varying factor of the 'waitcnt'??

    Can the Propeller pick up readings that low in voltage as in input?

    Thanks,
    Dan
  • Dan EDan E Posts: 61
    edited 2011-01-21 09:48
    Thanks for the help, I'll take a look a that link, reposting my other question in a separte thread is a good idea, since what I am looking for now is a different topic than initially.

    Dan
Sign In or Register to comment.