Trigger to make signal 40kHz.

AKil

Member
Hi, I'm doing a project and I am using the picaxe 18M and I need some inputs, such as when I managed to make the black line follower CNY70, just yesterday with the LDR program readadc and now I need to send a signal and seen trigger, I can program a signal 25microsegundos to be a frenuencia of 40khz and can be sent to a transducer?
 

Andrew Cowan

Senior Member
I'm not quite sure on everything you are asking, but this may help:
1) You can generate a continual output wave useing the pwmout command (on certain pins).
2) You can generate short pulses using the pulsout command (on all output pins).

Hope this helps!

A
 

AKil

Member
Its ok :) i gonna make pulse out to transfer to transducer :) bvut now i want to get 8 pulse to make :S u know any ? or i need put 8 times to make, i make a counter ... and after i make pulsein?
 

AKil

Member
Its right , i'm making a ulktrasonic :) , i see sfr005 , in picaxe web i find a ultrasonic range sensor explication :) , how to make a pulse and all.
 

hippy

Ex-Staff (retired)
If I've understood correctly, the requirement is to send a short burst of 40kHz to an ultrasound transducer, that short burst consisting of eight 25us active pulses with 25us spacing between each.

I've seen similar eight pulse requirements in DIY ultrasound range finders but I've never seen any explanation as to why eight pulses are required; can more or less be used ? That may make things easier.

However many pulses, I don't think that's possible using just an 18M though it should be possible using PWMOUT plus some external logic, a counter and some gating to allow only eight pulses through.

It should be possible to use HSEROUT on an X1 or X2 with a 40,000 baud rate. HSEROUT 0,($55) would send five pulses ( start bit plus four data bits ), HSEROUT 0,($55,$F5) should send eight pulses with the required timing. It would be worth checking with a scope that the timing is correct but I would expect the data to be sent back-to-back.

An 18X can have its SFR's poked to send bytes at 40,000 using the internal UART and I think back-to-back data transmission can be achieved.

Getting the transducer activated is only half the story; detecting an echo and being able to determine the time is the other half, and probably more than half the work. All-in, it's easier to use a dedicated module like the SRF04 / SRF05 which is much easier to interface to.
 
Last edited:

AKil

Member
Hello i¡'m making my circuit with picaxe 18M he make puls 40Khz and MAX 232 to make 20 VPP with picaxe 18M i make pulsout 1,2 ( 1 = pinout and 2 is 20microseco but i need 25micros :S i dont know how to make that but i can't put 2.5) and with Max232 he make 0 to 10v and 0 to - 10 and transfer to trandsducer and when signal come i amplify that and i pulsin with picaxe i dont know that its correct :S or i can put a comparator when it detect i compare with 5 v signal and i connect with picaxe another theme is i want calculate the time with the picaxe , any command to clk? to know time , i have distance and propagation m/s :)
 

AKil

Member
HEllo i have tested pwmout 2,24,50 on the 2 is pin 24 is the result of wizard calculte to 40khz and duty is 50% UP and 50% down. that its ok to make signal to pass in Max232 and up to 20Vpp butr now i want to make only 8 cyccles.
 

BeanieBots

Moderator
The 18M does not support the "PWM" command which can stipulate the number of cycles so you will have to do it in hardware. (or use 08M/X2)

There are several methods you could use.
If you are not too worried about the exact number of cycles, (and I don't believe it to be critical), simply AND the signal with another output so that you can 'enable' the pulse stream for a fixed time period using pulsout.

Alternatively, feed the stream into a counter (eg 4017) and use a suitable Q output to dissable the stream (via a gate) after the required count.
 

AKil

Member
But pwm with 40Khz and 50% duty and 4017 to make 8 cycles are nice but i think the best solution are pulsout and pulsin :S but i dont know what is range and what i can do with range,, ihave picaxe 18M agfter that i amplify with Max232 and after that the signal go to transducer, to get echo i amplify signal and dont know if i can connect direly to the picaxe to receive pulsin :S , i can know the time with thwe picaxe with readclk?
 

hippy

Ex-Staff (retired)
But pwm with 40Khz and 50% duty and 4017 to make 8 cycles are nice but i think the best solution are pulsout and pulsin
PULSOUT may allow you to generate the required pulse but cannot execute quickly enough to give you the correct inter-pulse spacing. You will not get a 40kHz burst that way.


but i dont know what is range and what i can do with range
That's a physical, mechanical, component, circuit and implementation issue. The approach there is to prototype and see what results you get.


dont know if i can connect direly to the picaxe to receive pulsin
That depends on how your incoming echo detect circuit is designed. To use PULSIN you will need a pulse which is a measure of time between trigger and echo received. This may require additional circuitry.


i can know the time with thwe picaxe with readclk?
READCLK will not be useful for determining the time between triggering and echo. You will have to use PULSIN or some other mechanism.
 

AKil

Member
Then I would give a pulse output 40kHz rather a frencuency to 8 cycles of 40khz, after passing through the max232 and has what I need to be passed to 20Vpp and a transducer with a frequency of 40Khz, but I think as a pulse Pwmout or not pulsout which would be best suited for the reception I think that amplify and taken to picaxe serious enough, or so I'm doing a little circuit SFR004



Picaxe -> MAX 232 -> O ) ) ) ) ) ( ( ( ( ( O -> Amplifier -> Picaxe

I think that can be ok :S
 

hippy

Ex-Staff (retired)
I was assuming the intent is to make a cloned Daventech SRF04 ( or similar ) using a PICAXE rather than PICmicro ...

Schematic - http://www.junun.org/MarkIII/datasheets/SRF04.pdf

Timing - http://www.junun.org/MarkIII/datasheets/SRF04_timing.pdf

There are two issues there which have been recognised -

* The ability to generate the required 40kHz burst.

* The mechanism to determine the time between trigger and echo.

The dedicated PICmicro is capable of running at higher speeds and performing timing which the PICAXE by itself cannot. It is therefore necessary to use additional circuitry and/or alternative mechanisms to perform the same task.

This is also, I suspect, where the 'eight pulse' 40kHz burst idea originates from. Presumably there needs to be enough pulses to get the transducer outputting, but not too many to mask the echo.

I have seen a design on Google which use a single pulse and a very simple echo detect circuit as you suggest but I do not know how effective that would be.

The best way is to try it and see what happens. The only thing missing in your sugested setup is, how does the receiving PICAXE know when the pulse was sent ? It can read the ultrasonic pulse ( some time after it was sent ) but could not determine the time delay without an additional input. You also need a means to turn that time delay into a pulse which PULSIN can read.
 
Last edited:

AKil

Member
i dont know that :( ,, in the circuit srf04 the trigger are coming out of the pic and pic only make 8 cycles of the triger? after that max232 make 20vpp? is that right?

But i want generate pulse in my picaxe and make 8 pulse of 40Khz but all program i see they use pulsout :O and u say me i can't make a puls of 40Khz with that.
 

hippy

Ex-Staff (retired)
i dont know that :( ,, in the circuit srf04 the trigger are coming out of the pic and pic only make 8 cycles of the triger? after that max232 make 20vpp? is that right?
That is correct.

But i want generate pulse in my picaxe and make 8 pulse of 40Khz but all program i see they use pulsout :O and u say me i can't make a puls of 40Khz with that.
That is also correct.

A single PULSOUT can give a 25us pulse ( SETFREQ M8:pULSOUT pin,5 ) but consecutive PULSOUT's will not give a 40kHz burst; the gap between pulses will be longer than 25us.

Consecutive 25us pulses with 25us inter-pulse gaps can be generated with PWMOUT but you will need to enable and disable PWMOUT or gate those pulses to give just a number of pulses rather than a continuous stream.

If you want only eight pulses ( each guaranteed to be 25us with 25us gap ) you will almost certainly have to use some circuitry to ensure only eight pulses are issued.
 

hippy

Ex-Staff (retired)
You can use "PWMOUT 3,24,50:pWMOUT 3,OFF" to give a burst of pulses ( and at 8MHz you can adjust that to make it fewer pulses, or under-clock and get more pulses ), but if you want an exact number of pulses you will have to count them and use external hardware to count them and gate them, or provide some other pulse gating mechanism.
 

AKil

Member
and the command are PWMout 3,24,50 pin,frequency,duty its ok? and what is :pWMout 3,OFF pin off its 2 command different 1 is put cycles and other shutdown no?
 

hippy

Ex-Staff (retired)
That's what the Programming Editor PWMOUT Wizard suggests for 40kHz. The first turns PWM on, the second turns it off. More details in PICAXE Manual 2 - Basic Commands.
 

AKil

Member
main:

pwmout 2,24,50
pwmout 2,off
goto main

Thats only make 1 pulse of that frequency or make more?
 

hippy

Ex-Staff (retired)
More.

Pin number has to be 3 for PICAXE-18M, not 2 - Please see PWMOUT command description in PICAXE Manual 2 - Basic Commands
 

hippy

Ex-Staff (retired)
but i dont see pwmout off in picaxe basic command and i have 118 pages :O
You probably have an older manual. The one I have is "Version 6.8 02/2009", 221 pages. "PWMOUT pin,OFF" is listed on page 139.

But anyway; trust me, "PWMOUT 3,OFF" turns off PWM on a PICAXE-18M. Or you can try it for yourself with a LED+R connected between Output Pin 3 and 0V ...

#Picaxe 18M
Do
Pause 1000 : PwmOut 3,255,255
Pause 1000 : PwmOut 3,OFF
Pause 1000 : PwmOut 3,255,25
Pause 1000 : PwmOut 3,OFF
Loop

That LED should then show Bright-Off-Dim-Off etc.
 

hippy

Ex-Staff (retired)
i can specifie more than pin , example for a pwmout i want to make a count for 2 pins :S
At the same time ? Probably not or you could simply send the same signal to two transducers.

In which case the PICAXE-14M which can route PWM using HPWM might be a good choice.
 

AKil

Member
Now only i want to make a signal of 40Khz with picaxe to tranfer to MC1458 amplifier to put 20 Vpp to tranducer.

I want a command to make a signal of 40Khz if i make a pwmout 2,24,50 : pause 200 microseconds and i put pwmout 2,off its ok i calculte i cycle are 25 micros 8 are 200micros with that i can make 8 cycles no?
 

hippy

Ex-Staff (retired)
Each PICAXE command takes approximately 250us at 4MHz and for as long a PWMOUT is active, those 25us pulses will be coming out. How many pulses you will get depends on which PICAXE you are using, what PICAXE clock frequency you are operating at and where exactly the code is in program memory.

If you want an exact number of pulses you will need to count them or gate them in some way.

The easiest thing may be to set up a test program and look at what PWMOUT generates on an oscilliscope. Then decide if that is acceptable or not.
 

AKil

Member
ok thx u i gonna test

main:
for b0 =1 to 8
pwmout 2,24,50
pause 200?
next b0
end

tell me if that is good for test
 

Andrew Cowan

Senior Member
That will create a 40kHz wave for 1.6 seconds. Is that what you want? To pause 200microseconds, you may want to use the pulsout command on an unused pin.

A
 

AKil

Member
Can u show me a code of that ?but if i make pulsout they only make a 20micros pulse how he make 8 cycles in aSFR08 i dont understand that :O and when i test to see in a osicilicop i only see a very fast tic .
 
Top