Sign in

username:

password:



Not a member?

Search hc11



Search tips

Subscribe to hc11



Ads

Discussion Groups

Discussion Groups | M68HC11 | HC11 & Sonars

Technical discussions about Freescale Microcontrollers: M68HC11. (Freescale Semiconductor is a Subsidiary of Motorola).

HC11 & Sonars - richiras - Dec 5 5:31:00 2005

Hi,
I think this group can help me :
I'm going to put 8 sonars (Devantech SRF04) on my robot based on a
homemade board.
The code that drives the robot is wrote in assembly, than I'm
searching for some samples of code written for 68HC11 to drive sonars ;
on Acroname.com I found the sample for Handy Board, but this is
written in IC ;
do u have something that helps please ??





(You need to be a member of hc11 -- send a blank email to hc11-subscribe@yahoogroups.com )


Re: HC11 & Sonars - BobG...@... - Dec 5 9:57:00 2005


In a message dated 12/5/2005 4:34:14 A.M. Eastern Standard Time,
richiras@rich... writes:

than I'm
searching for some samples of code written for 68HC11 to drive sonars ;
==================================================
Since this is the domain of digital signal processing, I'm sure there is
much more help to be had in c. All the good sonar stuff is either classified or
way too computation intense for an 8 bit cpu with sw floating point. Is this
an autonomous underwater vehicle? What kind of hydrophones do you use? [Non-text portions of this message have been removed]




(You need to be a member of hc11 -- send a blank email to hc11-subscribe@yahoogroups.com )

Re: HC11 & Sonars - Paul B. Webster VK2BZC - Dec 5 17:22:00 2005

On Mon, 2005-12-05 at 08:57 -0500, BobGardner@BobG... wrote:

> Is this an autonomous underwater vehicle? What kind of hydrophones do
> you use?

I'm pretty sure he has no intention whatever of getting the thing near
water, and is referring to "Polaroid"-style modules of some
unfortunately, so-far-unspecified type.

--
Cheers,
Paul B.




(You need to be a member of hc11 -- send a blank email to hc11-subscribe@yahoogroups.com )

Re: HC11 & Sonars - Mike McCarty - Dec 5 18:05:00 2005

Paul B. Webster VK2BZC wrote:
> On Mon, 2005-12-05 at 08:57 -0500, BobGardner@BobG... wrote: >>Is this an autonomous underwater vehicle? What kind of hydrophones do
>>you use? > I'm pretty sure he has no intention whatever of getting the thing near
> water, and is referring to "Polaroid"-style modules of some
> unfortunately, so-far-unspecified type. Why do you say that? From his post:

> I'm going to put 8 sonars (Devantech SRF04) on my robot based on a
> homemade board.

http://www.acroname.com/robotics/parts/R93-SRF04.html

Mike
--
p="p=%c%s%c;main(){printf(p,34,p,34);}";main(){printf(p,34,p,34);}
This message made from 100% recycled bits.
You have found the bank of Larn.
I can explain it for you, but I can't understand it for you.
I speak only for myself, and I am unanimous in that!





(You need to be a member of hc11 -- send a blank email to hc11-subscribe@yahoogroups.com )

Re: HC11 & Sonars - Mike McCarty - Dec 5 18:08:00 2005

richiras wrote:
> Hi,
> I think this group can help me :
> I'm going to put 8 sonars (Devantech SRF04) on my robot based on a
> homemade board.
> The code that drives the robot is wrote in assembly, than I'm
> searching for some samples of code written for 68HC11 to drive sonars ;
> on Acroname.com I found the sample for Handy Board, but this is
> written in IC ;
> do u have something that helps please ??

Maybe.

I went and looked at the website, and see the C there. Why
do you insist on assembler? Is this a class project? If so,
be assured that your professor is reading this. If you need
help understanding the C and/or translating it, I can
probably help.

Mike
--
p="p=%c%s%c;main(){printf(p,34,p,34);}";main(){printf(p,34,p,34);}
This message made from 100% recycled bits.
You have found the bank of Larn.
I can explain it for you, but I can't understand it for you.
I speak only for myself, and I am unanimous in that!





(You need to be a member of hc11 -- send a blank email to hc11-subscribe@yahoogroups.com )

Re: HC11 & Sonars - Paul B. Webster VK2BZC - Dec 6 6:36:00 2005

On Mon, 2005-12-05 at 16:05 -0600, Mike McCarty wrote:
> Why do you say that?

OK, I was reading too fast (as clearly, was Bob). I was primarily
making the point that this was a "standard" land-based robot.

> http://www.acroname.com/robotics/parts/R93-SRF04.html

That certainly looks very much like the Polaroid modules in behaviour,
possibly more logic-compatible (TTL levels? What are they?) in terms of
supply voltage - I think the Polaroid expected 6V. But I have to say -
nothing *looks* as good as the Polaroid ones (single disc, gold surface,
lovely black perf plate)!

--
Cheers,
Paul B.




(You need to be a member of hc11 -- send a blank email to hc11-subscribe@yahoogroups.com )

Re: HC11 & Sonars - Richi - Dec 6 11:21:00 2005

Well,
this is a continuation of an old project wrote in
assembler that drives a robot :
68HC11 brain on a board made in univ. driving 3 step
motors !!
At this moment it isn't useful to translate 2000 rows
of code from assembler to C !!
Is there a simple way ??
__________________________________________
Yahoo! DSL – Something to write home about.
Just $16.99/mo. or less.
dsl.yahoo.com




(You need to be a member of hc11 -- send a blank email to hc11-subscribe@yahoogroups.com )

Re: HC11 & Sonars - Mike McCarty - Dec 6 13:09:00 2005

Richi wrote:
> Well,
> this is a continuation of an old project wrote in
> assembler that drives a robot :
> 68HC11 brain on a board made in univ. driving 3 step
> motors !!
> At this moment it isn't useful to translate 2000 rows
> of code from assembler to C !!
> Is there a simple way ??

No, there is not. So, what kind of help do you need?
Do you need a translation from C into assembler of the
routines on the website?

To put it another way, do you understand C at all? If so,
then you should be able to translate it yourself. If not,
then make a stab, and we'll give you some help.

Mike
--
p="p=%c%s%c;main(){printf(p,34,p,34);}";main(){printf(p,34,p,34);}
This message made from 100% recycled bits.
You have found the bank of Larn.
I can explain it for you, but I can't understand it for you.
I speak only for myself, and I am unanimous in that!





(You need to be a member of hc11 -- send a blank email to hc11-subscribe@yahoogroups.com )

Re: HC11 & Sonars - autostaretx - Dec 6 13:20:00 2005

--- In m68HC11@m68H..., Richi <richiras@y...> wrote:
>
> Well,
> this is a continuation of an old project wrote in
> assembler that drives a robot :
> 68HC11 brain on a board made in univ. driving 3 step
> motors !!
> At this moment it isn't useful to translate 2000 rows
> of code from assembler to C !!
> Is there a simple way ??

Well, the device's description page sums it up:
----
Calculating the Distance
The SRF04 provides an echo pulse proportional to distance.
If the width of the pulse is measured in uS, then dividing
by 58 will give you the distance in cm, or dividing by 148
will give the distance in inches. uS/58=cm or uS/148=inches.
-------------------

So tie the "trigger" to one IO pin, and the "echo" to another,
trip the trigger, and time how long before the "echo" is
asserted. Divide and conquer.

Your choice on how to handle the timing: count loop iterations
or set up an interrupt and/or use one of the hc11's timers.

If you want to handle multiple sonar units, you get to choose
if you devote lots of the hc11's IO pins to them (two each),
or if you externally "multiplex" them so one hc11 pin can
trigger any of the 8 sonars. And only one hc11 pin needs
"listen" for a response. Three other pins would drive the
one-of-8 mux.
If you don't feel like mux'ing, you could have one-per-each
trigger lines, and "wire OR" all of the echos to a common
listener pin.

For the timing loop? 20 lines of assembly

If you're willing to have your robot work in "sonar units",
you don't even need to divide.

I didn't notice the link to the C code, so i can't comment on
what the other 1980 lines of code were doing (probably talking
to humans, always a waste of code...).

have fun
--dick





(You need to be a member of hc11 -- send a blank email to hc11-subscribe@yahoogroups.com )

Re: Re: HC11 & Sonars - Mike McCarty - Dec 6 14:30:00 2005

autostaretx wrote:
> --- In m68HC11@m68H..., Richi <richiras@y...> wrote:
>
>>Well,
>>this is a continuation of an old project wrote in
>>assembler that drives a robot :
>>68HC11 brain on a board made in univ. driving 3 step
>>motors !!
>>At this moment it isn't useful to translate 2000 rows
>>of code from assembler to C !!
>>Is there a simple way ?? > Well, the device's description page sums it up:

[snip]

> Your choice on how to handle the timing: count loop iterations
> or set up an interrupt and/or use one of the hc11's timers.

The C example uses PORTA.7 and TIC3 set to trigger on falling
edge.

[snip]

> I didn't notice the link to the C code, so i can't comment on
> what the other 1980 lines of code were doing (probably talking
> to humans, always a waste of code...).

It's his assembly which is 2000 lines. The C is a little short
routine.

Mike
--
p="p=%c%s%c;main(){printf(p,34,p,34);}";main(){printf(p,34,p,34);}
This message made from 100% recycled bits.
You have found the bank of Larn.
I can explain it for you, but I can't understand it for you.
I speak only for myself, and I am unanimous in that!





(You need to be a member of hc11 -- send a blank email to hc11-subscribe@yahoogroups.com )

Re: HC11 & Sonars - BobG...@... - Dec 6 14:49:00 2005


In a message dated 12/6/05 10:22:28 A.M. Eastern Standard Time,
richiras@rich... writes:

At this moment it isn't useful to translate 2000 rows
of code from assembler to C !!
Is there a simple way ??
=====================
Read the assembler. Understand the algorithm it is implementing. Express
that algorithm in c. I bet the resulting assembler is less than 2000
instructions! [Non-text portions of this message have been removed]




(You need to be a member of hc11 -- send a blank email to hc11-subscribe@yahoogroups.com )

Re: HC11 & Sonars - Richi - Dec 7 11:22:00 2005

Yes, I understand "easy" C :-)
that means that I've never worked with interrupts,
than I will probably spend more time tyin' translatin
this code instead of writing some new routines...but
anyway I'll be working on something never tried !!
Just searching for support...

Thanks
__________________________________________
Yahoo! DSL – Something to write home about.
Just $16.99/mo. or less.
dsl.yahoo.com




(You need to be a member of hc11 -- send a blank email to hc11-subscribe@yahoogroups.com )

Re: Re: HC11 & Sonars - Richi - Dec 7 11:34:00 2005

Thank U for your support,
I've already installed a 3bit multiplexer on the
board, than I'll drive it with portb pins (3,4,5);
yes, than one pin will ping (PA7) and one pin will
echo (PA0).

What about the timing process during the multiplexing
??
Should I wait avoiding interferences ??

2000 rows to drive the robot and talk using a
protocol,
than I'll send a packet when gated sonars data on a 8
bit variable (8 sonars on/off) :
do I need to use interrupts ??

__________________________________________
Yahoo! DSL – Something to write home about.
Just $16.99/mo. or less.
dsl.yahoo.com




(You need to be a member of hc11 -- send a blank email to hc11-subscribe@yahoogroups.com )

Re: HC11 & Sonars - Mike McCarty - Dec 7 12:48:00 2005

Richi wrote:
> Yes, I understand "easy" C :-)
> that means that I've never worked with interrupts,
> than I will probably spend more time tyin' translatin
> this code instead of writing some new routines...but
> anyway I'll be working on something never tried !!
> Just searching for support...
>
> Thanks

No problem. Be glad to help. What I saw was very simple
C. And the hard part of interrupts has nothing to do with
language, really.

Mike
--
p="p=%c%s%c;main(){printf(p,34,p,34);}";main(){printf(p,34,p,34);}
This message made from 100% recycled bits.
You have found the bank of Larn.
I can explain it for you, but I can't understand it for you.
I speak only for myself, and I am unanimous in that!





(You need to be a member of hc11 -- send a blank email to hc11-subscribe@yahoogroups.com )

Re: Re: HC11 & Sonars - Mike McCarty - Dec 7 13:00:00 2005

Richi wrote:
> Thank U for your support,
> I've already installed a 3bit multiplexer on the
> board, than I'll drive it with portb pins (3,4,5);
> yes, than one pin will ping (PA7) and one pin will
> echo (PA0).
>
> What about the timing process during the multiplexing
> ??
> Should I wait avoiding interferences ??
>
> 2000 rows to drive the robot and talk using a
> protocol,
> than I'll send a packet when gated sonars data on a 8
> bit variable (8 sonars on/off) :
> do I need to use interrupts ??

Interrupts are a tool like anything else. Generally, they
should be avoided, especially in real time systems. Here
are some reasons:

(1) multiple contexts of execution are hard to debug
(2) if you actually need multiple tasks [another thing
to avoid if possible, see (1)] it messes up the scheduler's
job, since it takes priority over task switching
(3) they can make stack usage difficult to compute

That said, sometimes interrupts (and multitasks) are
just the right tool for the job. Usually real time
programs are just big infinite loops looking for stuff
to do.

I recommend using an input capture.
If your "main loop" runs fast enough, then
you can simply trigger the sonar, and set a flag
indicating that you are waiting. At the time you trigger
the sonar, grab the timer counter. Each time round
the loop, increment a counter. If the counter gets too
big, you know that no echo is going to arrive, and
you can retrigger and grab. OTOH, if the TIC flag
gets set before you "time out" the activity, then
you can compute the time between the trigger and
the echo. Just use 1100 feet per second as the
speed of sound, and you can compute the round trip
distance. Make sure that your "time out" timer is
long enough that truly no echo is going to be detected,
or you may compute things as being "really close"
due to a left-over echo arriving just after a trigger.

If your "main loop" does *not* run fast enough, then
you may well need an interrupt to act on an echo.
If the echo came too soon, then you know collision is
imminent, and you can halt the robot and set a flag
in the interrupt handler. Then the main loop can take
whatever other actions may be needed.

Anyway, try a rough translation of the C, and we'll give
help in refining it.

Mike
--
p="p=%c%s%c;main(){printf(p,34,p,34);}";main(){printf(p,34,p,34);}
This message made from 100% recycled bits.
You have found the bank of Larn.
I can explain it for you, but I can't understand it for you.
I speak only for myself, and I am unanimous in that!





(You need to be a member of hc11 -- send a blank email to hc11-subscribe@yahoogroups.com )

Re: HC11 & Sonars - autostaretx - Dec 7 13:09:00 2005

--- In m68HC11@m68H..., Richi <richiras@y...> wrote:
>
> Thank U for your support,
> I've already installed a 3bit multiplexer on the
> board, than I'll drive it with portb pins (3,4,5);
> yes, than one pin will ping (PA7) and one pin will
> echo (PA0).
>
> What about the timing process during the multiplexing ??

That entirely depends upon what you're -doing- with eight
sonars (why 8? (beyond "i have 8")).
Do you -need- all 8 to report all of the time?

Without referring to the spec sheet (i neglected to bookmark it),
from first principles it takes about 12 milliseconds for the
maximum 2 meter range of the sensor (speed of sound is a foot
per millisecond, more or less).

Is the robot moving? If so, how much trouble can it get into
if you devoted your attention to only one sensor for that 12 ms?

This is the trade-off when you're using a multiplexor:
every sonar on its own private m68hc11 pins gives you the
-finest- control, but at the cost of -using- all of those
valuable pins. (of course, you're already using 5 pins,
so raising that to 9 (one trigger, 8 echos) isn't -that-
much more, depending upon your needs for the others).

> Should I wait avoiding interferences ??

The easy way is to only deal with one at a time.

> 2000 rows to drive the robot and talk using a protocol,
> than I'll send a packet when gated sonars data on a 8
> bit variable (8 sonars on/off) :
> do I need to use interrupts ??

They let you do "other things" while waiting for the echo.
Interrupts are the most -flexible-, in that you -can- do
"other things" (such as monitor motor speeds, blink lights,
see if someone's sending a message, etc.).
But if -all- you're doing is waiting for the echo, then
other factors come into play: wouldn't this be a good time
to -learn- to use interrupts? Here's your chance.

Me? In a hobby usage i usually do both: first a programmed
loop to play with the sensor (until i get it nailed down),
and -then- drop it into the "clean driver" model.

My apologies for getting the C<-->assembly direction backwards.
(the dangers of posting pre-coffee)

have fun
--dick





(You need to be a member of hc11 -- send a blank email to hc11-subscribe@yahoogroups.com )

Re: Re: HC11 & Sonars - Author Unknown - Dec 12 14:50:00 2005

Richi,

One imagines we will need 8 separate locations for the 8 sonars to respond to. This looks like a bit of code that wants to branch to the checksonar routine 8 times with no idea where the outputs from each sonar are going. At a minimum the BRA checksonar probably should be a BSR and checksonar will end with an RTS.

I would think the checksonar would take a parameter of which sonar to sample and the "return value" (D, X, or Y registers or some fixed location or a stack value)will be the sonar result from that address.

I think you would do well to diagram the process and outputs you indent before jumping into some code to run the addresses.

Hope that helps,
Jim
>
> From: Richi <richiras@rich...>
> Date: 2005/12/12 Mon AM 11:42:11 EST
> To: m68HC11@m68H...
> Subject: Re: [m68HC11] HC11 & Sonars
>
> Thank You Mike,
> At the moment I'm writing the routine the drives the
> 3bit multiplexer using PORTB pins 3,4,5 (xx000xxx -->
> xx111xxx).
> What about this code :
>
> * muxsonar : the variable selecting the sonar
>
> mux EQU *
> BCLR muxsonar,#%00111000
> loopm EQU *
> LDAA muxsonar
> ADDA muxsonar,#%00001000
> ANDA #%01000000
> BEQ RTS * end of multiplexing loop
> BRA checksonar
> BRA loopm
>
> Can it works ??
> Calling checksonar the first thing that I'll do will
> be :
> BCLR PORTB,#%00111000
> BSET PORTB,muxsonar
> to set the bits respective to the selected sonar !!
> Is there a simpler way ??
>
> __________________________________________________
> ">http://mail.yahoo.com >
>
> Yahoo! Groups Links




(You need to be a member of hc11 -- send a blank email to hc11-subscribe@yahoogroups.com )

Re: HC11 & Sonars - Velja - Dec 13 15:43:00 2005

On my homepage

http://www.ptt.yu/korisnici/c/v/cveve/projects.html you can find distance meter fith Polaroid modul (from old polaroid camera).
I used 68hc11f1 in single chip mode. Display is LED with SPI interface chip
driven

I hope it help

Velja




(You need to be a member of hc11 -- send a blank email to hc11-subscribe@yahoogroups.com )

Re: HC11 & Sonars - richiras - Dec 16 5:14:00 2005

Your explication of the code is, as always, great...even if my problem
on the code was due to misunderstanding and was so simple !!
Now I can put all myself in translation and optimization of the code
!! Thanx !!

I think that, in my particular case, the problem of the recovery time
doesn't really exist, just because the 8 sonars are being readed
sequentially, hence never used two consecutive times !!
Nop ?? --- In m68HC11@m68H..., Mike McCarty <Mike.McCarty@s...> wrote:
>
> Mike McCarty wrote:
>
> [snip]
>
> I forgot to mention another possible problem with
> this code, which I did not address. It only gives
> the SONAR device a recovery time if the SONAR device
> detects an echo. This may not be correct, and is
> related to why I don't like returns from the middle
> of loops. If the device doesn't need the recovery time if
> there is no echo, then this is ok, but if the device
> needs recovery time even when an echo is not detected,
> then this code is *not* ok.
>
> Mike
> --
> p="p=%c%s%c;main(){printf(p,34,p,34);}";main(){printf(p,34,p,34);}
> This message made from 100% recycled bits.
> You have found the bank of Larn.
> I can explain it for you, but I can't understand it for you.
> I speak only for myself, and I am unanimous in that!




(You need to be a member of hc11 -- send a blank email to hc11-subscribe@yahoogroups.com )

Re: Re: HC11 & Sonars - BobG...@... - Jan 1 19:36:00 2006

Interesting thread about acoustic ranging. Sort of like radio ranging. 12
usec is a 'radar mile', time to go out and back. Rule of thumb for audio is 'ms
per foot'. You you need to listen for long enough for the ping to propagate
out and back. If your pulse repetition frequency is faster than your round
trip travel time, you get the 'blind spot' problems the radar guys all worked
out in the early days. So I havent heard anyone mention the max distance yet.
Is it 3 feet? if so, ping, wait 6ms, no echo, no wall within 3ft. But if you
ping again, and there is a wall at 6ft, you'll get the echo from the previous
ping, and now you think there is a wall at 3 ft. Interesting problem. [Non-text portions of this message have been removed]




(You need to be a member of hc11 -- send a blank email to hc11-subscribe@yahoogroups.com )

Re: Re: HC11 & Sonars - BobG...@... - Jan 2 15:39:00 2006


In a message dated 1/2/2006 12:41:15 P.M. Eastern Standard Time,
Mike.McCarty@Mike... writes:

More than just "sort of". It used to be fairly common practice,
during the design of waveguides and horns and antennae, to use
ultrasound for testing. Just as an example, the wavelength of
a 3GHz electromagnetic wave is 0.1 meter. Coincidentally, the
wavelength of a 3353 Hz tone in air is 0.1 meter. One can
pump 3353 Hz tones through the plumbing and evaluate the design,
without having to deal with dangerous microwaves.

There are some differences, as sound is longitudinal whereas
electromagnetic waves are transverse, but in unimodal stuff
it doesn't make any difference.

=========================================
That explains why the guys that invented the diffuser lenses for tweeters at
JBL all used to work at radar companies.
[Non-text portions of this message have been removed]




(You need to be a member of hc11 -- send a blank email to hc11-subscribe@yahoogroups.com )

Re: Re: HC11 & Sonars - Tony Papadimitriou - Jan 4 15:09:00 2006

----- Original Message -----
From: "Mike McCarty" <Mike.McCarty@Mike...>
To: <m68HC11@m68H... > richiras wrote:
>
> [snip]
>
> > BCLR TFLG1,x,#$FE *Clear IC1F before next edge (complem of $01)
>
> This instruction has an incorrect mask. It should be

Actually, it seems correct because if I remember well we want to set the bit
to clear the flag, no?

BCLR is read-modify-write, so the already set bit will be rewritten back to
clear the flag. All other bits should be written as zeros to prevent
affecting the remaining flags. This use is recommended by Mot, even though
I personally find it confusing. I'm happier with a plain LDA #?? / STA ??
sequency that is straight forward to most readers.

> Mike

tonyp@tony...




(You need to be a member of hc11 -- send a blank email to hc11-subscribe@yahoogroups.com )

RE: Re: HC11 & Sonars - Redd, Emmett R - Jan 4 17:29:00 2006

> -----Original Message-----
> From: m68HC11@m68H...
> [mailto:m68HC11@m68H...] On Behalf Of Tony Papadimitriou
> ----- Original Message -----
> From: "Mike McCarty" <Mike.McCarty@Mike...>
> To: <m68HC11@m68H... > > richiras wrote:
> >
> > [snip]
> >
> > > BCLR TFLG1,x,#$FE *Clear IC1F before next edge (complem of $01)
> >
> > This instruction has an incorrect mask. It should be
>
> Actually, it seems correct because if I remember well we want
> to set the bit
> to clear the flag, no?
>
> BCLR is read-modify-write, so the already set bit will be
> rewritten back to
> clear the flag. All other bits should be written as zeros to prevent
> affecting the remaining flags. This use is recommended by
> Mot, even though
> I personally find it confusing. I'm happier with a plain LDA
> #?? / STA ??
> sequency that is straight forward to most readers.
>
> > Mike
>
> tonyp@tony...
Unrelated to the set-bit-to-clear-flag register: When I want to use an
instruction like BCLR whose argument is the complement of the bit(s) I
am interested in, I write it like this:

BITX EQU Whatever
BITY EQU Whateverelse

BCLR Register,X,-1-BITX-BITY ;Clears BITX and BITY for
such-and-such reason.

As Mike points out to not use explicit numbers, -1 could be replaced by
a label. This also keeps from having to code:

COMBITX EQU ComplementOfWhatever

and doubling up on the labels.

HTH

Emmett Redd Ph.D. mailto:EmmettRedd@Emme...
Associate Professor (417)836-5221
Department of Physics, Astronomy, and Materials Science
Missouri State University Fax (417)836-6226
901 SOUTH NATIONAL Dept (417)836-5131
SPRINGFIELD, MO 65897 USA

"When I was a child, I spake as a child, I understood as a child, I
thought as a child: but when I became a man, I put away childish
things," like being too embarrassed to ask questions which my peers
might think as stupid.




(You need to be a member of hc11 -- send a blank email to hc11-subscribe@yahoogroups.com )