Monday, February 15, 2021

PIC18F4550 Basic ADC Programming In CCS PICC

Introduction To ADC Module Of PIC18F4550

 

PIC18F4550 has a 10-bit ADC module. There are 13 analog input channels within PORTA and PORTB.


These analog input pins are multiplexed with digital input pins. By default, they are analog input pins.


Voltage Reference

There two analog voltage reference pins - VREF+ (RA3) and VREF-(RA2). these two pins are optional. 


They could be wired to external voltage reference source, or internally wired to VDD and GND, by software default setting. However, the total reference voltage must not exceed 5 V DC in magnitude.



Clock Source

Clock source fed to the ADC module come from its internal ADC RC oscillator, or the MCU clock source with programmable prescaler, up to 1:64.



Interfacing And Programming

 

Unlike writing a program in a low level language like assembly language, using a high level C programming language could make it done in a short time. CCS PICC provide a lot of peripherals libraries for those PICMicro devices including the PIC18F4550.




Those programmings in assembly need to know about the technical details of the module, especially the registers setting the make the peripheral to operate properly. However in a high level C for embedded controllers, those technical details were summarized in a few C syntax of its function library.




CCS PICC ADC Functional Overview

All functions list below make a configuration and the operation of the ADC module.

  1. setup_adc(mode) - select adc mode like on/off, adc clock etc.
  2. setup_adc_port(value) - set the number of available pins on the targeting device. The reference voltage pins could be include here.
  3. set_adc_channel(channel) - select the specific channel to convert.
  4. read_adc(mode) - start the conversion and return the result
  5. adc_done() - it's useful for testing the result. It return 0 if the conversion is completed.

By default the ADC result is 8-bit wide even the device's ADC is 10-bit. To use the device's full 10-bit resolution, use the #DEVICE ADC=10 after the device header file declaration.

Interfacing And Programming

AN0 is the ADC channel 0 locates at RA0 of PORTA. This analog input channel read an analog input voltage value up to +5 V DC. The result is by default 8-bit. This 8-bit result display at the 8-bit PORTD output.
I configure the ADC clock to fed from its internal RC oscillator. Voltage reference for the ADC is internally wired to VDD and GND. MCU supplies at + 5 V DC. An external crystal is a 20 MHz crystal oscillator. 

PIC18F4550 Basic ADC Programming In CCS PICC
Schematic Diagram

Source stored in GitHub gist.

Click here to download archive of this example.

PIC18F4550 Basic ADC Programming In CCS PICC
A running 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 (56) 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 (47) Master/Slave (1) MAX7221 (1) MCP23017 (5) MCP23S17 (4) Meter (3) MikroC (2) Motor (15) MPLABX (71) 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 (3) SPI (24) STM32 (6) STM32 Blue Pill (6) STM32CubeIDE (6) STM32F103C8T6 (6) SysTick (3) temperature sensor (11) Thermometer (21) Timer/Counter (31) TM1637 (2) UART (7) Ultrasonic (4) Voltmeter (7) WDT (1) XC16 (2) XC8 (94)