A
Joined: 19 Mar 2012 Posts: 1
|
Read ADC Maxbotic EZ1 Ultrasonic Sensor |
Posted: Mon Mar 19, 2012 8:34 pm |
|
|
Hi, By using Maxbotic EZ1 Ultrasonic Sensor, I have problem to read ADC value. This is my code
Code: |
#include <16F877A.h>
#device adc=8
#FUSES HS, NOWDT, NOLVP, NOPROTECT
#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
#include <LCD.C>
#include <Stdio.h>
#include <math.h>
#byte PORTA=5
#byte PORTB=6
#byte PORTC=7
int8 value;
float x;
void main()
{
set_tris_a(0xff); //RA as input
set_tris_b(0x00); //RB as output
set_tris_c(0x80); //RC as output & input
setup_port_a(ALL_ANALOG);
setup_ADC(ADC_CLOCK_INTERNAL);
set_adc_channel(0);
lcd_init();
do
{
value = read_adc();
x = Value * (5.0/255);
lcd_gotoxy(1,1);
lcd_putc("Bit:");
printf(lcd_putc,"%u",Value);
lcd_gotoxy(1,2);
lcd_putc("Volt:");
printf(lcd_putc,"%3.2f",x);
delay_ms(200);
lcd_putc("\f");
}
while(TRUE);
}
|
The value display at LCD but the analog value not stable. Maybe I'm wrong in calculation. From datasheet, analog output signal voltage is 9.8mV/inch.
refer http://www.maxbotix.com/documents/MB1010_Datasheet.pdf
So, how to calculate range detection from adc value?? Hope anybody can help me. |
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Mar 19, 2012 9:33 pm |
|
|
Quote: | but the analog value not stable
|
Read the ADC section of the 16F877A data sheet and find the correct
clock divisor to be used for a 20 MHz crystal. Then look in the 16F877A.h
file to find the correct CCS constant to use with setup_adc() below:
Quote: |
#include <16F877A.h>
#device adc=8
#FUSES HS, NOWDT, NOLVP, NOPROTECT
#use delay(clock=20000000)
setup_port_a(ALL_ANALOG);
setup_ADC(ADC_CLOCK_INTERNAL);
set_adc_channel(0);
|
16F877A data sheet:
http://ww1.microchip.com/downloads/en/DeviceDoc/39582b.pdf |
|