Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Ultrasonic Sensor Interfacing Zilog Microcontroller

Status
Not open for further replies.

xueyuanlu

New Member
Hello, I have a problem interfacing my microcontroller with an ultrasonic sensor. I want to create a system where the ultrasonic sensor is connected to a Zilog microcontroller, and the zilog with output the level of the distance detected by the microcontrollers using LEDS. For example, if the Ultrasonic sensor detects 5 inches, the the LED with light up as 00000101, where 1 signifies a lit led and 0 as unlit led. Here are the sensor and the microcontrollers that I have been using:

**broken link removed**
**broken link removed**
**broken link removed**

The one who sold us the sensor told us that in order to connect the sensor to microcontroller, we have to lift one foot of the R27 resistor and connect it to the Receive pin of the Sequencer. According to the guy there, the R27 resistor is used for serial communications.

and this is the program that I have made:

#include<ez8.h>
#include<sio.h>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

void delay(void) {

unsigned int y;
for (y=0; y<0xFFFF;y++);

}

void main(void) {
char x;
int m;


PCAF = 0x00;
PCOC = 0x00;
PCDD = 0x00;
PCHDE |= 0xFF;

init_uart(_UART0, _DEFFREQ, _DEFBAUD);

while(1) {
select_port(_UART0);

x = getch();
delay();
m = x;
PCOUT = m;
delay();
}

}

My problem with that program is that, whenever the sensor is pointed to any distance, the only LEDs that light are the one closer at MSB: 11100000 (where 1 - lit, 0 - unlit). I don't know what's wrong.

I tried to use an oscilloscope to view if the signal at the foot of the R27 resistor is right. The signal shows positive logic configuration, 1 - High, 0 - Low. I don't if it is directly compatible with the microcontroller, but the guy at the shop where I bought the sensor, I just have to connect it directly to the Receive pin.

I've also tried modifying the code in such a way that it'll look like this:

char ch;

ch = getch();
PCOUT = ch;

but the output is still the same. Can you help me here? thanks very much :)
 
Why are you not stepping through this code with the debugger and monitoring the variables to figure out the issue?

When you use a breakpoint in the debugger, what are you getting for x?
 
Why are you looking at the disassembly window? Create a watch variable in your watch window and step through the code or put a breakpoint after you receive your x variable. Check what you have received. If it's not what you expected, there could be any number of reasons for that. Divide up your issues and debug the problem. If you have a logic analyzer or a logging scope check the data line to make sure data is actually being sent.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top