I wish to operate a LVMAX Sonar EZ1 sonar rangefinder.

They say

With 2.5V - 5.5V power the LV-MaxSonar EZ1 provides very short to long-range detection and ranging, in an incredibly small package. The LV-MaxSonar-EZ1 detects objects from 0-inches to 254-inches (6.45-meters) and provides sonar range information from 6-inches out to 254-inches with 1-inch resolution. Objects from 0-inches to 6-inches range as 6-inches. The interface output formats included are pulse width output, analog voltage output, and serial digital output.

enter image description here

I wish to control this using an Altera DE2 Education and development board, User manual, Getting started guide

They say:

The Altera® DE2 Development and Education board is an ideal vehicle for learning about digital logic, computer organization, and FPGAs. Featuring an Altera Cyclone® II 2C35 FPGA, the DE2 board is suitable for a wide range of exercises in courses on digital logic and computer organization, from simple tasks that illustrate fundamental concepts to advanced designs.

I am not sure how I can do this. The two possibilities I see are the expansion headers and the rs232. But i have never used them and am not able to find any links on how to do analog read using the expansion headers. The rs232 serial interface just looks a lot more challenging.

  • 1
    \$\begingroup\$ You should be able to see for yourself we have no way of knowing what "the de2 board" is. This is not a real question in its current form. Fix it quickly or it will probably be closed. \$\endgroup\$ Commented Nov 13, 2011 at 0:21
  • \$\begingroup\$ @OlinLathrop, it is probably worth noting when you inform the user of such that the question will be closed quickly, but can be reopened when they have made necessary edits. \$\endgroup\$
    – Kortuk
    Commented Nov 13, 2011 at 4:53
  • 1
    \$\begingroup\$ @Kortuk - sounds like a good theory. Do you have any stats re the % of questions that ever get reopened? \$\endgroup\$
    – Russell McMahon
    Commented Nov 13, 2011 at 6:19
  • 1
    \$\begingroup\$ @RussellMcMahon, not at all, but if one is edited and flagged to me I have reopened. Normally a low quality question is that because the poster did not take the time to formulate a good question, which for simpler issues often finds the resolution. Or they are a one time visit. I have seen probably 10 question reopened over the last 3 months. You did just perform the edit to improve its quality after the user did the same. The issue is if you tell a user a close means they are done what is the point of trying when it is closed. All but 2 or 3 moderation actions are reversible. \$\endgroup\$
    – Kortuk
    Commented Nov 13, 2011 at 16:10
  • \$\begingroup\$ @RussellMcMahon, only diamond mods perform the non-reversible actions, which are mostly used for merging tags and destroying spammer accounts. In essence, since we are still somewhat short on users whom can vote to close and reopen, just flag a moderator and we can speed up the process significantly. As our community continues to get higher rep users it will become more run of the mill for users to do it themselves. I will note, every question I have seen edited to improve quality has been reopened, so they are reopened 100% of the time after quality corrections. \$\endgroup\$
    – Kortuk
    Commented Nov 13, 2011 at 16:12

2 Answers 2


RS232 looks like a straightforward way to interface the two devices.

You have to get the baud rate the same at each end, connect appropriate pins and deal with th eincoming data - s "simple matter of programming " :-).

Data output:

It sounds like the EZ1 can be persuaded to output RS232 data continually

enter image description here

Data input:

Page 42 of the DE2 users manual and
pages 26 & 27 of the DE2 Getting Started Guide
show how to configure an RS232 interface using the onboard PS/2 socket.

They advise that:

  • The DE2 Board uses the standard 9-pin D-SUB connector for RS-232 communications between PC and the board.
    The transceiver chip used is MAX232.

    For detailed information on how to use the chip, users can refer to the spec under C:\DE2\Datasheet\RS232. <- Probably on the supplied CD ROM Figure 3.11 shows the related schematics.
    The pin assignment of the associated interface is shown in Table 3.9.

As long as you do NOT have a "brown dot part" then the EZ1 Sonar can be easily configured to calculate range repeatedly and to output the results as a continual sequence of R232 strings. ie

  • TX – , When the *BW is open or held low, the TX output delivers asynchronous serial with an RS232 format, except voltages are 0- Vcc.

    The output is
    -an ASCII capital “R”,
    -followed by three ASCII character digits representing
    -the range in inches up to a maximum of 255,
    -followed by a carriage return (ASCII 13).

    The baud rate is 9600, 8 bits, no parity, with one stop bit.
    Although the voltage of 0- Vcc is outside the RS232 standard, most RS232 devices have sufficient margin to read 0-Vcc serial data.
    If standard voltage level RS232 is desired, invert, and connect an RS232 converter such as a MAX232.

enter image description here

*Brown dot parts: When BW pin is held high the TX output sends a single pulse, suitable for low noise chaining (no serial data)

  • \$\begingroup\$ will the voltage be a problem? can i connect the sensor directly to the board \$\endgroup\$
    – user591124
    Commented Nov 16, 2011 at 3:59
  • \$\begingroup\$ WARNING If you connect the MAX232 output on the DE2 to the EZ1 it will probably destroy the EZ1. There is no reason to do so. Do not try. \$\endgroup\$
    – Russell McMahon
    Commented Nov 16, 2011 at 5:47
  • \$\begingroup\$ You MUST learn to read and understand basic specifications or you will never progress and will always have to be asking people questions on matters that you should have learned about. In my answer, in the image at the top afer TX and again lower down it says: "Although the voltage of 0- Vcc is outside the RS232 standard, most RS232 devices have sufficient margin to read 0-Vcc serial data." It is saying that you can PROBABLY input RS232 data from the sensor to the DE2 | \$\endgroup\$
    – Russell McMahon
    Commented Nov 16, 2011 at 5:48
  • \$\begingroup\$ Will this be the output from the sensor ... 1(idle)0(start)1010010(82 - R in binary)1(stop-bit) 0(start)#distance in binary# 1(stopbit) \$\endgroup\$
    – user591124
    Commented Nov 25, 2011 at 3:15

Russell discussed the RS232, so I'll look at the other options.

The analog output is not really practical since the DE2 doesn't appear to have an ADC.

The PWM output would be pretty easy to use though. All you would need to do is connect one of the FPGA pins (set to input) to the PWM output, and use a timer on the FPGA to time the pulse width. Altera will probably have a generic PWM core you can set up appropriately and drop in. Or you can write your own pretty easily. Detect rising edge, start counter, detect falling edge, stop counter and calculate results.
For 147us per inch from the sonar, and say using the 50MHz clock on the FPGA, then you get 147us / 20ns = 7350 counts per inch. So divide the counter result by e.g. 73.5 and you have results in hundredths of an inch.

Whatever you are connecting, make sure the supply voltages are the same or the lower supply pin is tolerant of the higher supply (e.g. if the FPGA runs at 3.3V and the sonar at 5V, you need to make sure the FPGA pin is 5V tolerant)
Easiest way is to run the sonar at the FPGA IO supply (probably 3.3V, though could be less. Sonar says 2.5V-5.5V so it's within range) If the levels have to be different for some reason and there is no "tolerance", then you would need a level shifter. Since this would only be a one way data stream you could just use a simple resistive divider.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.