Recent Posts

Blogroll

                                          My PIC12F683 Development Board
Office Map Circuit diagram for each experiment may not be available separately because they are conducted with PIC12F683 development board that I made. So, the readers should first see the schematic of my development board.

Saturday, June 26, 2010

Experiment No. 3: 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).

2 comments:

Sexier You said...

That's so cool indeed. Amazing creation! I wanna make one for my own too.

discounted digital board

Sam said...

Hi Raj,
Thank you very much for sharing your ideas. I am a newbie to programming and successfully using it on 16F684 ; could you tell me how to modify your code to display analog voltage from one more channel, that is 2 analog voltages simultaneously.
Thanks in advance.
Sam.

Post a Comment

Online Embedded Systems Lab

This online laboratory teaches you the fundamentals of microcontroller-based embedded system development through a series of laboratory exercises. Most of the time, students and hobbyists could not afford expensive development kits and software to learn these things. These tutorials are prepared such that you will be building microcontroller projects at a minimum cost. Check this out