How to send pulse train at certain freq
Archiver
Posts: 46,084
Hi, everyone, I did some work to answer some of my own Questions:
I used an Oscilloscope to verify.
* Seems BS2 takes 1.4ms to execute command like "OUTPUT 7"
becasue I compared times for the following two cases:
Case(a)PULSOUT 0,100
PULSOUT 0,100
OUTPUT 7
Case(b)PULSOUT 0,100
PULSOUT 0,100
the question is any instruction set will take BS2 1.4ms to execute?
*I then used the shortest pulse (2 microseconds)
PULSOUT 0,1
PULSOUT 0,1
it pulsed high for 2 u sec as expected, then go to low for
about 220u sec, that's the shortest it can stay at low then
execute another high for 2 u sec, this is too long for my
application, is there any way to control BS2 to high 2 u sec,
then low for 2 u sec? Or shorten the distance between pulses.
* Will I shorten the time between pulse train by upgrading
to 50MHz SXchip ( I am using BS-2 now)? Looks like I should
get a 2.5 factor improvement?
Please help me if you have experience in this topic, actually I
would like to use FREQOUT if it cna do TTL 0, 5V output like a
pulse train
thanks, pete
--- In basicstamps@egroups.com, pwang@d... wrote:
> Dear Experts:
> I have a basic problem, I am not sure if I can solve this by
> upgrading
> to 50MHz SX2 from currently using 20MHz BS2.
>
> (1) my project:
>
> After receiving a positive edge on pin 1 on BS2, I need to
> output 128 pulses at a certain rate calculated previously,
> so I might need the pulse train sent at 2560 pulse/seconds (2560Hz)
> or 2540Hz, or 2530Hz, output at Pin0
>
> (2) I have tried
> FOR REP=1 TO 128
> PULSOUT 0,100
> NEXT
> but when I chedcked using OSC, seems it does take BS2 some time >0.5
> ms to come back from for loop and give another pulse
>
> I then used
> again:
> PULSE 0,100
> PULSE 0,100
> PULSE 0,100
> goto again
>
>
> to test, it seems better, because after it pulsout, it came back
low,
> then
> immediately PULSOUT, no delay in trying to execute loop
>
> (3)CAN I use FREQOUT command to do the task? I might need a TTL
> chip to make the signal to be TTL compatible 0-5V pulse? I checked
> FREQOUT with OSC seems a lot of strange signal, di have the sine
wave
> ripple corresponding to the freq I set, is this command only
> for analog Audio like loudspeaker?
>
> thanks very much
> pete, BS2 user
I used an Oscilloscope to verify.
* Seems BS2 takes 1.4ms to execute command like "OUTPUT 7"
becasue I compared times for the following two cases:
Case(a)PULSOUT 0,100
PULSOUT 0,100
OUTPUT 7
Case(b)PULSOUT 0,100
PULSOUT 0,100
the question is any instruction set will take BS2 1.4ms to execute?
*I then used the shortest pulse (2 microseconds)
PULSOUT 0,1
PULSOUT 0,1
it pulsed high for 2 u sec as expected, then go to low for
about 220u sec, that's the shortest it can stay at low then
execute another high for 2 u sec, this is too long for my
application, is there any way to control BS2 to high 2 u sec,
then low for 2 u sec? Or shorten the distance between pulses.
* Will I shorten the time between pulse train by upgrading
to 50MHz SXchip ( I am using BS-2 now)? Looks like I should
get a 2.5 factor improvement?
Please help me if you have experience in this topic, actually I
would like to use FREQOUT if it cna do TTL 0, 5V output like a
pulse train
thanks, pete
--- In basicstamps@egroups.com, pwang@d... wrote:
> Dear Experts:
> I have a basic problem, I am not sure if I can solve this by
> upgrading
> to 50MHz SX2 from currently using 20MHz BS2.
>
> (1) my project:
>
> After receiving a positive edge on pin 1 on BS2, I need to
> output 128 pulses at a certain rate calculated previously,
> so I might need the pulse train sent at 2560 pulse/seconds (2560Hz)
> or 2540Hz, or 2530Hz, output at Pin0
>
> (2) I have tried
> FOR REP=1 TO 128
> PULSOUT 0,100
> NEXT
> but when I chedcked using OSC, seems it does take BS2 some time >0.5
> ms to come back from for loop and give another pulse
>
> I then used
> again:
> PULSE 0,100
> PULSE 0,100
> PULSE 0,100
> goto again
>
>
> to test, it seems better, because after it pulsout, it came back
low,
> then
> immediately PULSOUT, no delay in trying to execute loop
>
> (3)CAN I use FREQOUT command to do the task? I might need a TTL
> chip to make the signal to be TTL compatible 0-5V pulse? I checked
> FREQOUT with OSC seems a lot of strange signal, di have the sine
wave
> ripple corresponding to the freq I set, is this command only
> for analog Audio like loudspeaker?
>
> thanks very much
> pete, BS2 user
Comments
My own measurement of that is 0.14 ms, not 1.4 milliseconds. At 140
microseconds, that is among the fastest executing instructions on the
Stamp2.
I have some of my own timing measurements posted at
http://www.emesystems.com/BS2speed.htm
supplemented by some observations made by Steve Parkis. It is a work in
progress.
> PULSOUT 0,1
> it pulsed high for 2 u sec as expected, then go to low for
> about 220u sec,
My figure agrees with yours on this one, 220 to 230 microseconds interpulse
time, depending on whether the pulse length is a constant or a variable.
> is there any way to control BS2 to high 2 u sec,
> then low for 2 u sec? Or shorten the distance between pulses.
As you have already found, an inline sequence
PULSOUT 0,1
PULSOUT 0,1
PULSOUT 0,1
can execute at up to about 4350 hertz. And you could change the overall
frequency with a fine adjustment of "xt" in PULSOUT 0,xt. A FOR NEXT loop
is very slow, adding about 800 microseconds per iteration, so the maximum
frequency with pulsouts in a FOR NEXT loop would be no more than about 950
hertz. I think you said in your earlier message that you were looking for
frequencies around 2000 or 3000 hertz.
> * Will I shorten the time between pulse train by upgrading
> to 50MHz SXchip ( I am using BS-2 now)? Looks like I should
> get a 2.5 factor improvement?
Yes, so with an inline sequence of pulsouts, you could get a frequency as
high as about 11000, and with the FOR-NEXT logic up to about 2400 hertz.
> would like to use FREQOUT if it cna do TTL 0, 5V output like a
> pulse train
The freqout command uses time-slot PWM with a 4.5 microsecond slot and a
1.15 millisecond cycle.
<http://www.emesystems.com/BS2misc.htm#PWM
The discrete frequencies for PWM vary from 666 hertz at minimum and maximum
PWM to 111khz. Only certain discrete base frequencies are produced. As
you see on the 'scope, the raw signal is a mess, particularly when it
superimposes the audio tone in freqout. I can't see how it will help with
your application.
Good luck!
-- Tracy Allen
Electronically Monitored Ecosystems
http://www.emesystems.com