Shop OBEX P1 Docs P2 Docs Learn Events
Basic Stamp timer command question — Parallax Forums

Basic Stamp timer command question

CSCNETCSCNET Posts: 3
edited 2009-07-25 02:30 in BASIC Stamp
Hello everyone.· I am a new member trying to write a Program for my Basic Stamp to run a timer at 1/125 HZ @ 70%.· I have tried the PWM command with no success and am now working with the Pulsout command.· I am able to program the 70 duty cycle with the Pulsout but how do I get the 1/125 Hertz?· Can anyone lead me in the right direction?
Thanks

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-07-24 17:03
    The PWM statement isn't really intended for producing a specific pulse width with a specific repetition rate. If you read the description, you'll see that it's intended for use with a low pass filter for producing a desired output voltage. The average "on" time is as specified, but this is produced by switching the output on and off very rapidly using a pseudo-random generator.

    As you've figured out, the PULSOUT statement is better for what you want to do. The problem is controlling the "off" time. The best way to do this is to use an unused I/O pin if you have that and alternate PULSOUTs on the pin you want and the unconnected I/O pin. The PULSOUT for the unconnected I/O pin will cause an accurately determined short delay for the "off" time and the PULSOUT on the desired I/O pin will cause an accurately determined "on" pulse. This will be in a loop and the GOTO or DO / LOOP will cause a short delay, so you'll have to adjust the "off" time PULSOUT accordingly.
  • CSCNETCSCNET Posts: 3
    edited 2009-07-24 20:36
    Thanks for the quick response.·

    So if I use pin 9 as my high and pin 10 as my low I believe each of these uses 140 microseconds.· I am going to need to do some math to figure out the DO LOOP or·GOTO on this one.

    Do I use the·"Pulsout·PIN 9, 700" command first and then the GOTO?· Will the GOTO command then give me my 1/125 Hertz·if I use the right number of Highs and Lows (8000 microseconds)?

    Thanks again
  • Mike GreenMike Green Posts: 23,101
    edited 2009-07-24 22:03
    low 9 ' Set pin 9 to output mode with the resting state being low
    myloop:
    pulsout 9,700 ' On a BS2, this causes pin 9 to be toggled for 1400us
    pulsout 10,3300 ' On a BS2, this causes pin 10 to be toggled for 6600us
    goto myloop ' This starts the pulse sequence over again

    There's a little overhead associated with each of these statements. Tracy Allen has a good analysis of the execution time of various statements. Go to www.emesystems.com and select the "app-notes" link at the bottom of the page.
  • CSCNETCSCNET Posts: 3
    edited 2009-07-25 02:30
    I set up the program and it seems to be working.· I won't know the results for sure until I put it on the Oscilloscope.· At that time I may need to adust.

    I also need to run a timer at 1/1000HZ @ 70%.· Would the same program work for it?

    (First) 125HZ = T = 1/125 = .008 msec/.000001 = 8000 microseconds @ 70% duty cycle

    (Second) 1000HZ = T = 1/1000 = .001 msec/.000001 = 1000 microseconds @ 70% duty cycle

    Pulsout 9,86····· Based on your last email this should toggle for 172us.

    Pulsout 10,413····· Based on your last email this should toggle for 826us

    Does this make sense?

    Thanks for your help
Sign In or Register to comment.