In this tutorial, we show how to use REOBoard to measure external signals. As we have already explained how to use PWM to change a LED's duty ratio, we are going to reuse that code and control the LED from a potentiometer.

About ADC

MSP430F5x has an ADC with 12 input channels. All these channels can be individually configured and allow to measure input voltage compared to several references. Before starting the description of the ADC program, we have to make a little piece of hardware as follows:

On the left, the schematic picture shows how the potentiometer is wired to the board. On the right, the picture actually shows the hardware. All REOBoard's extension connectors have ground and power, analog connector included. The only thing to be careful is to wire the central point of the potentiometer on A0. The + and - can be inverted without damage.

Pot

 BoardAndPot320

 

 

 

 

 

 

 

 

We are going to use A0 which is MSP430's first analog input.

The program

MSP430 ADC's conversion start can be started by several methods

  • Timing determined by ADC itelf
  • Conversion caused by another timer
  • Conversion without interrupt by calling a conversion function.

As the timers are heavily used by REOBoard, we are going to choose the 3rd solution: use a timer, and change the LED duty ratio proportionally to the potentiometer central pin voltage.

The code is somewhat longer than what we have made until now, so it will be attached at the end of this page.

The functions

For clarity purposes, the software has been split into functions.

  • void EnableLedPWM(void);

    This function configures the timer used for PWM. This timer will directly drive the LED. In the code below, the setup is made with the low frequency RTC clock (TASSEL_1). With this setting, you will observe the on and off duration that changes according to the potentiometer value. By setting to TASSEL_2, the PWM clock would be 24 MHz instead of 32k. This time, the LED will look almost continuous (depending on the TA0CCR0 value). But the LED wil glow with variable intensity.

  • void SetLedDuty(uint16 duty);

    This function sets the LED PWM duty cycle. The effect will depend on the timer frequency. If slow, the LED will blink with on and off state depending on the potentiometer value. If fast, the LED will appear to glow permanently, with low or high intentity depending on the potentiometer value.

  • void EnableADCTimer(void);

    This is the second timer. It will determine the measuremement rate.

  • void EnableADC();

    Sets up the ADC for single shot measurement.

  • uint16 ReadADCVal(void);

    Reads a single value of the ADC

Running the program

Running the program goes without surprises and should work at once if the wiring is right.

Download the C code

A summary of the first tutorials has been added as a downloadable zip file here.