ELE2303 WORKSHOP 4 – ADC conversion
Demo section
How to set up an ADC; measure an analog input on the PICsimlab simulator.
Problem section
1. Create your own project for a PIC18F4620 processor (assume Fosc = 10Mhz)
Initialise the ADC for channel 1 (AN1), output on ports D and B
Write a main program with an endless loop
Read the analog value of Pot 2 (linked to AN1)
Display the binary value on the LEDS. High byte to LATD low byte to LATB
No delay is required
Test on the PICSimLab simulator
Set the speed of the simulator to 10 MHz
Change the Left/right justification setting in the ADCON2 register, test again.
2. Create a conversion function (using the adc conversion code) which will read the
analog value on Pot2; combine the two result register values into an unsigned
integer and return it to the main program.
Call that routine from the main program instead of using the adc code you had
before and store the high byte to LATD and the low byte to LATB.
3. Write a new function that calls your conversion function and returns the voltage of
the Potentiometer as a floating point value (instead of an unsigned). Assume the
voltage is 0 to 5V fullscale.
Call that routine from the main program, test using the debugger to see it returns
the correct float value.
4. Alter the main program to use your conversion routine (the unsigned int version)
and try to display that value on the four 7-segment LEDs.
Homework section
Create a new project, for the PIC18F4620 processor.
Select the PICSimLab Simulator (for debugging)
Complete all the parts of the workshop above..