Recent Changes - Search:

Introduction to Microcontroller Programming

About PICmicro Chips

Clocking Your PICmicro Devices

E-Blocks

Flowcode Step By Step

PICmicro Projects

Labs

Using the ADC

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.

  1. Add an ADC component onto your project panel. Alter the connection so that it is connected to ADC 1 - this is the potentiometer on the Sensor board.
  2. Add a new macro and call it 'ADCmeasure'.
  3. Add a Component macro to the 'ADCmeasure' macro. Set it to 'GetInt' to read the value of the ADC into the variable 'ADCreading' that you set up previously.
  4. Drag a Calculation icon into the macro and enter 'volume = ADCreading / 10' into the Calculation field.

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.

Print - Search - Login

Page last modified on May 02, 2013, at 03:27 PM