eee305 microcontroller systems lecture 8: analogue to digital conversion using pic microcontrollers...

22
EEE305 Microcontroller Systems Lecture 8: Analogue to Digital Conversion using PIC microcontrollers and the C compiler (NB As of 18/04/13 this code uses the older HTC compiler, I will change it to the more modern XC8 compiler in class) Teaching resources are at www.eej.ulst.ac.uk My office 5B18, telephone 028 90 366364 My email [email protected] http://www.eej.ulst.ac.uk/~ian/modules/ EEE305 1/

Upload: dustin-ross

Post on 22-Dec-2015

218 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: EEE305 Microcontroller Systems Lecture 8: Analogue to Digital Conversion using PIC microcontrollers and the C compiler (NB As of 18/04/13 this code uses

EEE305 Microcontroller Systems

Lecture 8: Analogue to Digital Conversion using PIC microcontrollers and the C compiler

(NB As of 18/04/13 this code uses the older HTC compiler, I will change it to the more modern XC8 compiler in class)

Teaching resources are at www.eej.ulst.ac.uk

My office 5B18, telephone 028 90 366364My email [email protected]

http://www.eej.ulst.ac.uk/~ian/modules/EEE305 1/

Page 2: EEE305 Microcontroller Systems Lecture 8: Analogue to Digital Conversion using PIC microcontrollers and the C compiler (NB As of 18/04/13 this code uses

Datasheet Chapter 11

Page 3: EEE305 Microcontroller Systems Lecture 8: Analogue to Digital Conversion using PIC microcontrollers and the C compiler (NB As of 18/04/13 this code uses
Page 4: EEE305 Microcontroller Systems Lecture 8: Analogue to Digital Conversion using PIC microcontrollers and the C compiler (NB As of 18/04/13 this code uses
Page 5: EEE305 Microcontroller Systems Lecture 8: Analogue to Digital Conversion using PIC microcontrollers and the C compiler (NB As of 18/04/13 this code uses
Page 6: EEE305 Microcontroller Systems Lecture 8: Analogue to Digital Conversion using PIC microcontrollers and the C compiler (NB As of 18/04/13 this code uses
Page 7: EEE305 Microcontroller Systems Lecture 8: Analogue to Digital Conversion using PIC microcontrollers and the C compiler (NB As of 18/04/13 this code uses
Page 8: EEE305 Microcontroller Systems Lecture 8: Analogue to Digital Conversion using PIC microcontrollers and the C compiler (NB As of 18/04/13 this code uses
Page 9: EEE305 Microcontroller Systems Lecture 8: Analogue to Digital Conversion using PIC microcontrollers and the C compiler (NB As of 18/04/13 this code uses
Page 10: EEE305 Microcontroller Systems Lecture 8: Analogue to Digital Conversion using PIC microcontrollers and the C compiler (NB As of 18/04/13 this code uses
Page 11: EEE305 Microcontroller Systems Lecture 8: Analogue to Digital Conversion using PIC microcontrollers and the C compiler (NB As of 18/04/13 this code uses
Page 12: EEE305 Microcontroller Systems Lecture 8: Analogue to Digital Conversion using PIC microcontrollers and the C compiler (NB As of 18/04/13 this code uses
Page 13: EEE305 Microcontroller Systems Lecture 8: Analogue to Digital Conversion using PIC microcontrollers and the C compiler (NB As of 18/04/13 this code uses
Page 14: EEE305 Microcontroller Systems Lecture 8: Analogue to Digital Conversion using PIC microcontrollers and the C compiler (NB As of 18/04/13 this code uses
Page 15: EEE305 Microcontroller Systems Lecture 8: Analogue to Digital Conversion using PIC microcontrollers and the C compiler (NB As of 18/04/13 this code uses
Page 16: EEE305 Microcontroller Systems Lecture 8: Analogue to Digital Conversion using PIC microcontrollers and the C compiler (NB As of 18/04/13 this code uses
Page 17: EEE305 Microcontroller Systems Lecture 8: Analogue to Digital Conversion using PIC microcontrollers and the C compiler (NB As of 18/04/13 this code uses

C Code to read ADC and O/p reading

Page 18: EEE305 Microcontroller Systems Lecture 8: Analogue to Digital Conversion using PIC microcontrollers and the C compiler (NB As of 18/04/13 this code uses

Last week’s code to use USART serial port

Page 19: EEE305 Microcontroller Systems Lecture 8: Analogue to Digital Conversion using PIC microcontrollers and the C compiler (NB As of 18/04/13 this code uses

Main code to test ADC

Page 20: EEE305 Microcontroller Systems Lecture 8: Analogue to Digital Conversion using PIC microcontrollers and the C compiler (NB As of 18/04/13 this code uses
Page 21: EEE305 Microcontroller Systems Lecture 8: Analogue to Digital Conversion using PIC microcontrollers and the C compiler (NB As of 18/04/13 this code uses

Further experiments

• If the ADC returns a number from 0 to 1024• Scale this to 80 (the width of a PUTTY screen)• Use a for loop

For(i=0;i<scaled_reading;i++){putchar(‘*’);} Printf(“\r\n”);

• This will print a “graph” across the screen.

Page 22: EEE305 Microcontroller Systems Lecture 8: Analogue to Digital Conversion using PIC microcontrollers and the C compiler (NB As of 18/04/13 this code uses

Making a Thermometer• Assume the thermistor initially reads 20 degrees • After holding for 60 seconds assume it reads 35 degrees• Scale the readings to display degrees• i.e If you get a reading of XX for 20 degrees and YY for 35

degrees.

20⁰C

35⁰C

XX YYZZ

??⁰C

Don’t forget to use variables of type float if they are needed