I'd like advice on .reading output from the circuit below from a thread on timing rocket cars. The code was written by "HippY"
I am measuring the initial velocity of a potato fired from a spud gun.
This is my first use of a Picaxe. I have built this circuit using two IR LEDs/phototransistor pairs, 25 cm apart anticipating an initial velocity of 25-50 m/sec.
I have built the circuit and downloaded the file. The signal is fed thru a 4011 quad NAND gate. With a scope I have confirmed visually that CounterIn, C.0, only pulses between the start and stop signals, passing my hands at varying speeds thru the sensors. So, the input and output work, but where do I read the output? The output should be a count of a train of pulses, correct? I then multiply the number displayed by the duration of each pulse ( currently .1oo usec) to get durution in useconds>
Once I get this to work I will use the Pwmout wizard to try and use 100kHz or even 1MHz.
The trouble is, where does the output go? I should see "ElaspedTime= XXX us. where?
I'm perplexed. When I run Simulate the program just cycles in the WaitForTimerStarted loop, despite the fact I can see a pulse train stop and start on the scope monitoring C.0.
After I download the program, which I have done many times, a curious screen shows up with Serial Terminal N 9600 8,N,1 in the Title bar, and spaces for input and output buffers below. I don't know what to do here, and have been just closing the dialogue box. Is this causing a problem?
Thanks
#Picaxe 28X2
#Terminal 9600
#No_Table
#No_Data
' ___ ___
' 1ST >----| \ ___ ___
' ___| & >O---.-------| \ .---| \
' | |___/ | | & >O---| | & >O---> Counter In
' |_____ _____| .---|___/ `---|___/ C.0
' \ / |
' X |
' _____/ \_____ `---------------------------< PWM Output
' | ___ | C.1
' |___| \ |
' ___ | & >O---'
' 2ND >----|___/
Symbol CounterIn = C.0
Symbol PwmOutput = C.1
Symbol T1CON_SFR = $CD
Symbol TMR1L_SFR = $CE
Symbol TMR1H_SFR = $CF
Symbol elapsedTime = w0
Symbol elapsedTime.lsb = b0
Symbol elapsedTime.msb = b1
Symbol lastElapsedTime = w1
SetFreq M8
Do
Gosub ConfigurePwmOutput
Gosub ConfigureAndResetTimer
Gosub WaitForTimerStarted
Gosub WaitForTimerStopped
Gosub CalculateAndDisplaySpeed
Loop
ConfigurePwmOutput:
PwmOut PwmOutput, 199, 400 ' 10kHz @ 8MHz, 50% duty
Return
ConfigureAndResetTimer:
PokeSfr T1CON_SFR, %00000111
PokeSfr TMR1L_SFR, 0
PokeSfr TMR1H_SFR, 0
Return
WaitForTimerStarted:
Do
PeekSfr TMR1L_SFR, elapsedTime.lsb
PeekSfr TMR1H_SFR, elapsedTime.msb
Loop Until elapsedTime <> 0
Return
WaitForTimerStopped:
Do
lastElapsedTime = elapsedTime
PeekSfr TMR1L_SFR, elapsedTime.lsb
PeekSfr TMR1H_SFR, elapsedTime.msb
Loop Until elapsedTime = lastElapsedTime
Return
CalculateAndDisplaySpeed:
SerTxd( "Elapsed Time = ", #elapsedTime, "00 us", CR, LF )
Return
I am measuring the initial velocity of a potato fired from a spud gun.
This is my first use of a Picaxe. I have built this circuit using two IR LEDs/phototransistor pairs, 25 cm apart anticipating an initial velocity of 25-50 m/sec.
I have built the circuit and downloaded the file. The signal is fed thru a 4011 quad NAND gate. With a scope I have confirmed visually that CounterIn, C.0, only pulses between the start and stop signals, passing my hands at varying speeds thru the sensors. So, the input and output work, but where do I read the output? The output should be a count of a train of pulses, correct? I then multiply the number displayed by the duration of each pulse ( currently .1oo usec) to get durution in useconds>
Once I get this to work I will use the Pwmout wizard to try and use 100kHz or even 1MHz.
The trouble is, where does the output go? I should see "ElaspedTime= XXX us. where?
I'm perplexed. When I run Simulate the program just cycles in the WaitForTimerStarted loop, despite the fact I can see a pulse train stop and start on the scope monitoring C.0.
After I download the program, which I have done many times, a curious screen shows up with Serial Terminal N 9600 8,N,1 in the Title bar, and spaces for input and output buffers below. I don't know what to do here, and have been just closing the dialogue box. Is this causing a problem?
Thanks
#Picaxe 28X2
#Terminal 9600
#No_Table
#No_Data
' ___ ___
' 1ST >----| \ ___ ___
' ___| & >O---.-------| \ .---| \
' | |___/ | | & >O---| | & >O---> Counter In
' |_____ _____| .---|___/ `---|___/ C.0
' \ / |
' X |
' _____/ \_____ `---------------------------< PWM Output
' | ___ | C.1
' |___| \ |
' ___ | & >O---'
' 2ND >----|___/
Symbol CounterIn = C.0
Symbol PwmOutput = C.1
Symbol T1CON_SFR = $CD
Symbol TMR1L_SFR = $CE
Symbol TMR1H_SFR = $CF
Symbol elapsedTime = w0
Symbol elapsedTime.lsb = b0
Symbol elapsedTime.msb = b1
Symbol lastElapsedTime = w1
SetFreq M8
Do
Gosub ConfigurePwmOutput
Gosub ConfigureAndResetTimer
Gosub WaitForTimerStarted
Gosub WaitForTimerStopped
Gosub CalculateAndDisplaySpeed
Loop
ConfigurePwmOutput:
PwmOut PwmOutput, 199, 400 ' 10kHz @ 8MHz, 50% duty
Return
ConfigureAndResetTimer:
PokeSfr T1CON_SFR, %00000111
PokeSfr TMR1L_SFR, 0
PokeSfr TMR1H_SFR, 0
Return
WaitForTimerStarted:
Do
PeekSfr TMR1L_SFR, elapsedTime.lsb
PeekSfr TMR1H_SFR, elapsedTime.msb
Loop Until elapsedTime <> 0
Return
WaitForTimerStopped:
Do
lastElapsedTime = elapsedTime
PeekSfr TMR1L_SFR, elapsedTime.lsb
PeekSfr TMR1H_SFR, elapsedTime.msb
Loop Until elapsedTime = lastElapsedTime
Return
CalculateAndDisplaySpeed:
SerTxd( "Elapsed Time = ", #elapsedTime, "00 us", CR, LF )
Return