View Full Version : Regarding triggering of sonar
NAVNEET ACHARYA
05-22-04, 02:34 PM
Sir,
Instead of using Timer pin I am using GPIO pin for triggering of
of sonar ,But I am having some problem with that,I am not
getting Readings properly.
Can I use GPIO PIn for this purpose?
My code is as :
HEX
: RANGE
D2A @ 127 / . ." in0."
;
: RANGE1
D0A @ 127 / . ." in1."
;
: PLS
PB0 OFF
PB1 OFF
10 0 DO PB0 ON PB1 ON LOOP
PB0 OFF
PB1 OFF
0 D2D ! ( ZERO TMRB1 CNTR REG. AND WASTE 10uS
0080 D2F ! (
7880 D2E ! (
RANGE
0 D0D ! ( ZERO TMRA1 CNTR REG. AND WASTE 10uS
0080 D0F ! (
7880 D0E ! (
RANGE1
;
EVERY C350 CYCLES SCHEDULE-RUNS PLS
: Z DECIMAL BEGIN D EMIT RANGE ?TERMINAL UNTIL ;
Please Give me some suggestion regarding the program.
Regards,
RMDumse
05-22-04, 03:07 PM
Originally posted by NAVNEET ACHARYA
Can I use GPIO PIn for this purpose?
Well, yes, but you need to keep the timing simular to what was done with the timer pin.
: PLS
PB0 OFF
PB1 OFF
10 0 DO PB0 ON PB1 ON LOOP
PB0 OFF
PB1 OFF
0 D2D ! ( ZERO TMRB1 CNTR REG. AND WASTE 10uS
0080 D2F ! (
7880 D2E ! (...
Well, this is strange to me. You turn off two pins. You do a DO LOOP turning the pins on over and over. Then you turn them off again. ... I don't really know why you did all that.
Here's the first thing to understand. The initiation pulse is just 10uS long (or maybe longer). The OO function ON or OFF is not fast. It is very slow, because it is made for beginners, so it does all sort of setting up and initialization of the ports, etc., assuming someone using ON or OFF as an OO wouldn't know about such things. That's good and its bad. It's good, because its easy to use. It's bad, because it does lots of things that are unnecessary (if you do your own setup) over and over each time it is called. So, the OO words aren't really recommended for a fast operation like running this sonar. The original code went right to the register of the timer pin and made it high in one store action, and made it low in another. So it was much faster.
None the less, the OO port words might work. All you want to do is take the line high once, zero the counter, and take the line low.
So using OO words, it would look like this:
: PLS
PB1 ON
0 D2D ! ( ZERO TMRB1 CNTR REG. AND WASTE 10uS
PB1 OFF
0080 D2F ! (
7880 D2E ! (
PB0 ON
0 D0D ! ( ZERO TMRA1 CNTR REG. AND WASTE 10uS
PB0 OFF
0080 D0F ! (
7880 D0E ! (...
So this will keep the pulses close to the zeroing of the timers, and doesn't have any loops in it.
Now for a final comment, you've added print statement calls to PLS. PLS must run 100 times a second per the statement
EVERY C350 CYCLES SCHEDULE-RUNS PLS
So everything that comes out the serial channel must be over in 1/100th of a second. At 9600, you can send 1 character in 1/1000th of a second. So at most, you could send ~9 or 10 characters in the scheduler, without overrunning. You use labels in0. and in1. which make up 8 characters right there. Since your range number will likely be more than a character each, you will break the IsoStructure paradigm, and your program will run late, and leave almost nothing left in waste cycles for the foreground routine to run. You might want to move your print statements out to the foreground to let the background run correctly.
Let me know if the OO words on the ports works with the sonar now.
RMDumse
05-22-04, 03:09 PM
Ahhh... one more thing. Check to be sure PB1 goes with TMRB1 and PB0 with TMRA1, or, rearrange the code. I couldn't tell from reading your program which went with which. Notice, though, I used them one at a time, sequentially, rather than both on and both off at the same time. If you wanted to do both sonars at once, you wouldn't have to use two lines. Just let one output go to both sonars.
hotstepper
05-27-04, 01:04 PM
HI
We had thought of using the GPIO pins for triggering to save Timer pins for other devices. Our plan is to connect 8 sonars. Mr. Dumse has talked about using the same trigger for both the sonars. I would like to know if the same can be done for all the sonars, i.e. trigger all of them with one timer pin. My application would benefit from the simultaneous triggering of all the sonars.
Awaiting your reply..
Hotstepper
RMDumse
05-27-04, 01:26 PM
Well, I haven't tried multiple sonars, but give typical fanout limitations, its not unusual to have one output run up to 10, or perhaps even 16, loads of a similar type. I don't know exactly the internal circuitry of the sonar (not my product) but I do think they are PIC microprocessor based, so an output from our board would very likely trigger 8 sonar boards.
Remember running all the sonars at once will put a tremendous spike into the supply. The spike could be enough to cause problems, such as spurious resets. Additional caps at each sonar might help overcome this. I'd try a .1 in parallel with a 10uF or even 100uF at each sonar.
Also remember putting that much sonar energy into the environment will make for lots of bounced reflections, and the various sonars might thereby interfere with each other. Something to keep in mind.
vBulletin v3.0.7, Copyright ©2000-2012, Jelsoft Enterprises Ltd.