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.

dsPIC30F6014a ADC

Status
Not open for further replies.
Hi,
Sorry for misunderstood your comment earlier. I'm not a good programmer and sorry for lack of knowledge in programming. I changed the code as advised, However when I pumped 1.2V dc voltage to ADC channel 5 and channel 6 pins they are not displaying correct values. I tested with my earlier code (printf) and it works as expected. Please advised.

frahman3

CSS:
#include <30F6014A.h>
#device ADC=12
#include <float.h>
#include <string.h>
#fuses NOWDT, NOPROTECT, PUT64, BORV27
#use delay (clock=58982400, xtal=7372800)
#use rs232(baud=9600,UART1,ERRORS)

unsigned char adc_value_5[20];
unsigned char adc_value_6[20];

unsigned char ert_adc_value_5;
unsigned char ert_adc_value_6;
unsigned char ert_voltages_5;
unsigned char ert_voltages_6;

void task1()
     {
      set_adc_channel(5);     //read from channel 0
      delay_us(10);           //delay is required after setting channel and bef.read
      //read_adc(ADC_START_ONLY);
      ert_adc_value_5=read_adc();    //starts conversion & store it in value
      ert_voltages_5=(ert_adc_value_5)*5000/4096;// last result of last conversion
      sprintf(adc_value_5,"Ch05=%u",ert_voltages_5);
      }
      
void task2()
      {
      set_adc_channel(6);     //read from channel 0
      delay_us(10);           //delay is required after setting channel and bef.read
      //read_adc(ADC_START_ONLY);
      ert_adc_value_6=read_adc();    //starts conversion & store it in value
      ert_voltages_6=(ert_adc_value_6)*5000/4096;// last result of last conversion
      sprintf(adc_value_6,"Ch06=%u",ert_voltages_6);
      }
      
      
void main(void)                     //void=nothing, no return value
{

set_TRIS_D(0x0000);
SETUP_ADC(adc_OFF);
   setup_adc_ports(ALL_ANALOG); 
   setup_adc_ports(sAN0 |sAN1|sAN2|sAN3|sAN4|sAN5|sAN6|sAN7|sAN8|sAN9|sAN10|sAN11|sAN12|sAN13|sAN14|sAN15, VSS_VDD);
   setup_adc(ADC_CLOCK_DIV_64 | ADC_TAD_MUL_2);
   //setup_adc(ADC_CLOCK_INTERNAL);
  
while(TRUE)
 //if (kbhit())                      //check if a character has been received
    // c = getc();                   //read character from UART
      {
      task1();
      task2();
      puts(adc_value_5);
      puts(adc_value_6);
      puts("Ch99=9999");       
     }//end while
}//end main
 
Hi,
Thanks for the advice and support. It is very kind of you to share your knowledge. At the moment I try to use the existing code although it is long but I can understand how it works. This are the display values using the above code and with '\n' after the puts function. My objective is to send continuous adc data (without blank rows) to labview. The problem is the values are still incorrect.

frahman3

Dislpayed value with putc '\n' funtion.
with newline.jpg

Dispayed value without putc '\n' function
without newline.jpg
 
Hi,
no problem! Everyone learns, I've been programming for decades and I'm still learning.

If you are adding the \n to the string as part of the printf() / sprintf(), you do not need the extra putc().

The continuously varying numbers imply the ADC does not have enough settling time; try temporarily changing the delay after setting the channel to 50uS rather than 10uS and see what happens?


What results do you get with your original code?

Please also try changing all the ert_ variables from unsigned char to unsigned int, and see what results you get then?
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top