CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Read ADC Maxbotic EZ1 Ultrasonic Sensor

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
A



Joined: 19 Mar 2012
Posts: 1

View user's profile Send private message

Read ADC Maxbotic EZ1 Ultrasonic Sensor
PostPosted: Mon Mar 19, 2012 8:34 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Mar 19, 2012 9:33 pm     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group