Introduction to Microcontroller Programming
About PICmicro Chips
Clocking Your PICmicro Devices E-Blocks Flowcode Step By Step
PICmicro Projects
Labs |
Using the ADC<^< Setting up the LCD | Course Index | Finishing Touches >^> So far you have set up two interrupts, and three macros which are called from the main routine. In this next part of the project you will set up a further macro that will measure the signal on an analogue input.
You should have something like this: ![]() The process of sampling the ADC is a two stage one: first sample the value and then read the value into a variable. The PICmicro we are using here actually has up to 8 ADC inputs - AN0 to AN8. Internally however the PICmicro only has one Analogue to Digital Converter. Each of the 8 inputs can be switched to the ADC using internal analogue switches. This gives you a clue as to why the process of getting an analogue input into your program is a two stage process: internally Flowcode sets up the analogue switch to connect to the relevant input, then it takes a reading. The ADC inside the PICmicro has a resolution of 10 bits. This means that to make use of the full range of the ADC you need to use a variable of type Int: a 16 bit variable. The value you read will vary between 0 and 1023. However we are used to seeing Volume presented as 0 to 10, or 0 to 100. Because of this we can quickly divide the ADC reading by 10 to get a scale of 0 to 102 as our volume setting. You should by now be able to think of programming techniques to cap the value at 100. <^< Setting up the LCD | Course index | Finishing Touches >^> |