Problems with Microcontroller Projects? You may face many Problems, but do not worry we are ready to solve your Problems. All you need to do is just leave your Comments. We will assure you that you will find a solution to your project along with future tips. On Request we will Mail you the Codes for Registered Members of this site only, at free service...Follow Me.

Analog to Digital Converter with PIC12F683

As mentioned before, 4 out of 6 GPIOs in a PIC12F683 also provide analog-to-digital converter inputs with 10-bit resolution. They are GP0-GP2, and GP4. In this experiment we will feed an analog voltage to one of the ADC inputs (say AN0, which is GP0) and display the output digital value on a hyper-terminal window on PC. The analog voltage will be simulated with the potentiometer on our board.

Experimental Setup:
Connect the output of potentiometer (POT2) to AN0 (pin 7). GP5 (pin 2) will serve as TX pin for Software UART so connect it to input Tx of TTL to RS232 Level Shifter circuit. Also connect Rx (2) and Gnd (5) of a RS232 port to the board. This is similar to what we did in Experiment No. 2.





Software:

/*
  PIC12F683 Experiment Board
  Experimen No. 3 : Read analog voltage from AN0 and diplay
  on Hyperterminal window on PC using Software UART.
  Date: 06/25/2010
*/
char Message1[] = "Digital Value= ";
unsigned int adc_value, backup=0 ;
char *temp = "0000", error;
int i;
void main() {
CMCON0 = 7;
TRISIO = 11;  // GPIO 0, 1, 3 Inputs; Rest are O/Ps
ANSEL = 0x01;
GPIO = 0;
// Define GPIO.3 as UART Rx, and 5 as Tx
error = Soft_UART_Init(&GPIO,3, 5, 9600, 0 );
Delay_ms(100);

do {
 adc_value = ADC_Read(0);


 if(adc_value != backup) {

  if (adc_value/1000)
   temp[0] = adc_value/1000 + 48;
  else
  temp[0] = '0';

  temp[1] = (adc_value/100)%10 + 48;
  temp[2] = (adc_value/10)%10 + 48;
  temp[3] = adc_value%10 + 48;

 for (i=0; i<= 13; i++) {
      Soft_UART_Write(Message1[i]);
      Delay_ms(50);
     }

 for (i=0; i<= 3; i++) {
      Soft_UART_Write(temp[i]);
      Delay_ms(50);
     }
     Soft_UART_Write(10); // Line Feed
     Soft_UART_Write(13); // Carriage Return

 backup = adc_value;
 }

 delay_ms(100);
 } while(1);
}

Output:
The digital value of input analog voltage will be displayed on hyperterminal window. The digital value will have range from 0-1023 (10-bit ADC).

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...

Recent Comments

Popular Projects

Give Support

Give Support
Encourage Me through Comments

Microcontroller Projects

Total Pageviews