Tuesday, August 25, 2020

PIC16F84A Reads Analog Voltages From MCP3204 12-bit SPI ADC

Microchip MCP3204


MCP3204 is a 12-bit analog to digital converter (ADC). It's a discrete ADC IC with serial peripheral interface (SPI). There are four analog input channels, with two reference voltage pins. Using a 5 V supply voltage, the ADC conversion rate takes up to 100 ksps.


A simulating program.


For more numbers of analog input channel, MCP3408 has up to 8 analog input channel with the same functionalities.


A sample of MCP3204 from the device's vendor

Pin diagram


Both MCP3204 and MCP3208 come with DIP package and SMD package. MCP3204 is a 14-pin DIP or TSSOP package. Each pin function lists below.


MCP3204 pin function table from the device's datasheet


The 12-bit ADC creates a digital value of 4096 in decimal. We can find the digital equivalent to analog voltage as follow.


Digital output code for 12-bit ADC


SPI communication initiated by pulling the CS pin low. Data is shift out and in as below.


SPI communication with MCP3204


The first four bits of DIN are configuration bits for MCP3204/MCP3206. Setting these four bits could make varieties of ADC reading.


Configuration bits for the MCP3204


ADC reading could be a single-ended mode or a differential-pair mode, IN- and IN+.


CCS PICC Interfacing And Programming Using MCP3204 driver


PIC16F84A doesn't come with hardware SPI peripheral. However, using CCS PICC compiler interfacing with this device accomplished by software SPI library and the driver for MCP3204. A driver mcp3294.c is ready to use with some functions.


  1. adc_init() - call after the power up
  2. value = read_analog_mcp( channel, mode ) - read analog channel (0 to 3), when mode = 0 it read in differential mode otherwise single-ended mode.
  3. value = read_analog( channel ) - read analog channel (0 to 7) in single-ended mode.
  4. convert_to_volts( value, string ) - read analog value with equivalent analog voltage, and convert it to string "0.000".

In this example, I use this ADC to read four analog inputs channel in single-ended mode. These four values display on a character LCD.


Schematic Diagram


CCS PICC Source Code:

Note: The mcp3204.c and lcd.c is already come with the compiler. Click here to download this example in zip file.

The overall program consumes 81% of the flash memory in PIC16F84A.

Statistics of this program

A took a screen shot of this program from the simulator.

A simulating program.


No comments:

Post a Comment

Search This Blog

Labels

25AA010A (1) 8051 (7) 93AA46B (1) ADC (30) Analog Comparator (1) Arduino (15) ARM (6) AT89C52 (7) ATMega32 (54) AVR (57) CCS PICC (28) DAC (1) DHT11 (2) Display (105) Distance Sensor (3) DS18B20 (3) dsPIC (2) dsPIC30F1010 (2) EEPROM (5) Environment Sensor (4) esp8266 (1) I2C (29) Input/Output (67) Interrupt (19) Keil (5) Keypad (10) LCD (46) Master/Slave (1) MAX7221 (1) MCP23017 (5) MCP23S17 (4) Meter (3) MikroC (2) Motor (15) MPLABX (66) Nokia 5110 LCD (3) OLED (2) One-Wire (6) Oscillator (8) PCB (6) PCD8544 (3) PCF8574 (5) PIC (107) PIC12F (2) PIC16F628A (2) PIC16F630 (1) PIC16F716 (3) PIC16F818 (10) PIC16F818/819 (2) PIC16F84A (15) PIC16F876A (1) PIC16F877A (9) PIC16F88 (1) PIC16F887 (60) PIC18 (19) PIC18F1220 (4) PIC18F2550 (3) PIC18F4550 (12) PWM (11) RTC (8) Sensor (10) SH1106 (1) Shift Register (11) Shift Registers (2) SPI (24) STM32 (6) STM32 Blue Pill (6) STM32CubeIDE (6) STM32F103C8T6 (6) SysTick (3) temperature sensor (11) Thermometer (21) Timer/Counter (30) TM1637 (2) UART (7) Ultrasonic (4) Voltmeter (7) WDT (1) XC16 (2) XC8 (94)