Pwmout

hippy

Ex-Staff (retired)
From Post #34 ...

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.
 

inglewoodpete

Senior Member
From a design perspective, if you are to use a PICAXE, you have 2 options.

Use a PICAXE 08M, which supports the PWM command. The PWM command allows you to specify the number of pulses to output.

-or-

Use another PICAXE and add a gated counter to stop the output after 8 pulses. This will require 2 output pins from the PICAXE: PWM output and counter reset.
 

AKil

Member
I'm using a picaxe-18M i think have 8 Mhz inglewoo i dont understand the option with 2 outputs pins
 

hippy

Ex-Staff (retired)
The two output pins would be the PWMOUT itself plus a control line to allow counting of 8 pulses and passing those through.

The actual control circuit may need to be a little more complicated than simple gating of the PWM pulse train as you may need to turn the gating on between pulses or the first pulse may not be '40kHz'.

@ inglewoodpete : While PWM on the 08M allows the number of cycles to be specified those cycles would not necessarily be 40kHz.
 

inglewoodpete

Senior Member
Thanks for that point hippy - something I'd overlooked.

That leaves us with the gated counter. The PWM would need to clock the counter and the gating. Eg The gate would open on (lets say) the falling edge on the PWM then the counter would disable the gate on the 8th falling edge after that. My guess is that it could be done with about 3 additional chips.

Not impossible to do but it makes the SRF005 a much more attractive solution.
 

hippy

Ex-Staff (retired)
Thinking about it, the gate may not have to be synchronised ... turn PWMOUT off, turn the gate on, start PWMOUT should work. The counter would close the gate.

It should also be possible to use a monostable reset for the counter so it was cleared automatically when PWMOUT off, detectingte absence of pulses, which would bring us back to a single I/O line.

I agree it's a lot of work when the SRF005 does everything that's needed.
 

AKil

Member
OK i put the signal out i have 8 cycles of 40Khz but now i receives back and i amplify that signal to 5v but now how i have a question, when i put on pwmout i can put a crono to calcule how time need the signal to come back. CLK or any command special?.
 

hippy

Ex-Staff (retired)
OK i put the signal out i have 8 cycles of 40Khz but now i receives back and i amplify that signal to 5v but now how i have a question, when i put on pwmout i can put a crono to calcule how time need the signal to come back. CLK or any command special?.
You need some means to measure between the start of the signal being sent and the start of the echo being sent. You can do that by counting the time with something like ...

Gosub StartPulses
w0 = 0
Do While PinX = 0
w0 = w0+1
Loop

but that will have very coarse resolution ( probably around 1ms at 4MHz ) which will only allow inaccurate distance measurements,

Alternatively you can create a hardware signal such that a pulse is generated for the period between the pulses being sent and the echo received. This pulse length can then be read using a PULSIN. This is how the SRF005 does it.

The problem is that a PICAXE can only read a pulse with PULSIN where that pulse starts after it is executing the PULSIN. Thus you cannot send the pulses out and have the pulse activated then and be able to read it with PULSIN later.

You need a mechanism for triggering the pulses out and waiting for the PULSIN with the pulses being sent some time later after triggering. A second PICAXE could do this. You would effectively be replicating the SRF005 circuit for this second PICAXE which sees the trigger pulse, delays issuing the pulses and then provides the time pulse to be read by the initiating PICAXE.

Once you have that the master PICAXE can use the same code which it would with a genuine SRF005 ( as described in SRF005.PDF ) with maybe some minor adjustment ...

PulsOut trig,2
PulsIn echo,1,range
range = range * 10 / 58

The PICAXE on your 'clone SRF005' board has to wait for the trigger, delay, emit the U/S pulses and provide a pulse between start of sending and echo received. The diagram in SRF005.PDF shows this sequence of events and it is also in the SRF004 and SRF005 data sheets.

Alternatively you can produce a timing pulse using external logic which uses the first U/S pulse to start the pulse and the start of an echo pulse to stop it and use additional hardware to gate the pulse so that the timing pulse does not appear to the PICAXE until it is executing its PULSIN.

This is quite straight forward, fairly easy to do, but does take effort to do it. The cost in time is usually far greater than simply buying an SRF005 which is what most people would do as that also delivers a tried and tested result. For research, for the challenge or fun of doing it from first principles where time and effort is not important the previous solutions should get you what you need.
 

AKil

Member
Ok hmmm ok ok i use a big picaxe for make a pulsout to picaxe 08M that make a pwmout and when that pwm return picaxe08m make a pulse to big picaxe and the big measure the range measure the range that right¿
 

AKil

Member
What the difference make a trig 20 us or 10us or 30us and echo range 10us or 20us or 30us :S what is the most correct value to messure ,

let range = range * 10 / 58

that to covnerte range = time? to cm
 

AKil

Member
An example programa


Picaxe 18M

main:
pulsout trig,2
pulsin,1,range
let range = range * 10 / 58
goto main



Picaxe 08M

main:

dont know how to make to start
if pin0= high then
pulsout ,1
goto main


That make picaxe 18M make a puls to start the pwmout in 08M and when that come back make a puls to 18M to calc the cm.
 

hippy

Ex-Staff (retired)
The actual range conversion code depends on what pulse you have which represents the echo time which depends on how you design the code / circuit. The echo pulse length will differ depending on whether you start when the first U/S pulse is sent, before sending it, or after all 8 are sent.

The trigger pulse length has to be long enough for your U/S generator to see it. That too will depend on how you code your controller. An alternative to using trigger pulses is to look for change of state of the line as a trigger and this can be generated by simply toggling an output line. That in my opinion is a better way of generating a trigger and avoids the issue of how long pulses should be.
 

hippy

Ex-Staff (retired)
Master:
Do
Toggle trig
PulsIn 1, 1, range
range = range * ? / ?
Loop

UltrasoundController:
bit0 = pin0
Do
Do : While pin0 = bit0
bit0 = not bit0
:
Loop
 

hippy

Ex-Staff (retired)
Yes, there are many ways to pass a signal from one PICAXE to another; you can use whatever you find suitable.
 

AKil

Member
later i update a image for the final circuit i use read ADC i dont have mroe time to make ultrasonic and i need make control with radiofrequence , i make Picaxe 18M --> TL082 ---> Picaxe18M (read adc)
 

hippy

Ex-Staff (retired)
Post 21 : what that

That shows how to recognise a toggling trigger in response to your Post #16 , "dont know how to make to start". That shows how you would start / recognise the trigger.

Post 22

The ultrasound project was always going to to be complicated. If you have run out of time the solution may be to buy an SRF005 which does everything which you are attempting to do yourself.
 

hippy

Ex-Staff (retired)
Toggle switch to input or output pin no?

I'm not sure I understand the question. An output pin switching from high to low or from low to high ( toggling ) can be used as an event for indicating triggering. An input pin would monitor the state of the signal and use the change of state ( when toggled ) as its trigger.
 

AKil

Member
when i make pwmout

main:
pwmout 2,27,50
goto main

the signal somthimes dont appears in osciloscope , picaxe need a time to recharge ? or wait?
 

hippy

Ex-Staff (retired)
You are resetting the PWM everytime you issue the PWMOUT command. You want to issue it once and then leave it running ...

PwmOut 2, 27, 50
Do : Loop

Alternatively you can use STOP instead of DO:LOOP. Do not use END or only the PWMOUT command ( that has an implied END at the end of source code ) as that will turn PWMOUT off.
 

Andrew Cowan

Senior Member
Wait = measured in seconds
Pause = measured in milliseconds
Pauseus (Some PICs only) = measured in 10s of microseconds
Pulsout (on an unused pin) = measured in 10s of microseconds

Overclocking halves all these values.

A
 

AKil

Member
PWMOUT off
^

Error: Syntax error in this line!

:S ok ok and if i want to puse 200 microsecons how i can put ? pause 2?
 

BeanieBots

Moderator
The syntax is "PWMOUT PIN,OFF" but that didn't work for me either.
Just set the duty to zero or issue a "LOW Pin".

You can't do a 200uS pause with an 08M.
You could however do it with a PICAXE which supports pauseus.
Remember that the command overhead is ~250uS at 4Mhz, so you would need to overclock to get that down to > 200uS then fine tune with the pauseus command.
 

BeanieBots

Moderator
Using an 08M (which I assume you are), "pause 2" would be a delay of 2000uS.

If you had a PICAXE which supported pauseus
"pauseus 2" would be a delay of ~250 + 2*10uS = ~270uS

If you overclocked to twice the normal speed the 250uS would be halved to 125uS and the pauseus value would be in multiples of 5uS.

So, a pause for 200uS would be:

pauseus 15

(125uS + 15*5uS = 200uS)
 

BeanieBots

Moderator
You can't have a pause of 200uS then:(
However, I think you can make a delay close to 200uS if you have a spare output pin.

Hopefully somebody will correct me if I've this wrong.
First off, run at 8Mhz to get nominal command time down to 125uS
Then use pulsout which will have a resolution of 5uS.

Pulsout SparePin,15 should be quite close to 200uS.
You will need to experiment with the value to get it to the nearest 5uS.

Don't forget PWMout will need to be changed to take into account running at 8MHz.
 
Top