Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

unexpected A/D converted values.

Status
Not open for further replies.

thivanka321

Newbie level 5
Joined
Mar 10, 2010
Messages
8
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Location
Sri Lanka
Activity points
1,338
i wrote a programme in ccs c, to display A/D conversion values in hyperterminal.
i used pic 18f452. what i'm really converting is anlogue values taken from accelerometer.
but there is a unexpected problem. that is even without setting accelerometer to the A PORT of the pic, hyperterminal displays A/D converted values.
i checked the controler board whether there is a signals to A port. but there is not.
i;m sure pic controller board is ok. it works with other programmes ,well.

what is the reason for that? any problem with programme or what?
reply me soon.
Code:
#include "G:\ccsfiles\project2.h"


void main()
{
 float value;

   setup_adc_ports(AN0_AN1_AN2_AN3_AN4);
   setup_adc(ADC_OFF);
   setup_psp(PSP_DISABLED);
   setup_spi(FALSE);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_oscillator(False);

   // TODO: USER CODE!!
  setup_adc(ADC_CLOCK_DIV_8);
  // setup_uart(19200);
   set_tris_b(255);
  output_D(0);

     while(1)
   {
       set_adc_channel( 2 );
      delay_us(20);
     value = read_adc();
       
    
     printf("x = %8.3f\n\r",value);
      set_adc_channel( 1 );
      delay_us(20);
    value = read_adc();
     printf("y = %8.3f\n\r",value);

      set_adc_channel( 0 );
      delay_us(20);
      value = read_adc();
     printf("z = %8.3f\n\r",value);
     output_D(255);
}

}
 

even without setting accelerometer to the A PORT of the pic, hyperterminal displays A/D converted values
It can hardly do different, I think. The ADC doesn't care what's connected to it's input, it's simply measuring voltages. To check correct
ADC operation, you may want to connect a variable voltage source (e.g. a potentiometer connected to the 5V supply) to
the ADC and observe the readings.
 

I never worked with CCS C, but I believe the return value from read_adc() function should be an int rather than float. Try declaring variable value as int instead of float. And try averaging 2-3 samples to get the final value rather than using a single sample. This is not very important but may help you a bit if your hardware sits in a noisy environment.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top