In: Electrical Engineering
An MSP430 microcontroller system is to be designed with the following requirements:
The circuit operates from a 5 V supply with a decoupling capacitor.
2 LEDs (IF=15mA, VF = 1.9V) are connected to pins P1.2, P1.3. P1.4 on the microcontroller. These LEDs should have appropriate current limiting resistors and be connected in a sinking arrangement.
1 Push button should be connected to P2.1 using an external pull-up resistor
1 Push button should be connected to P2.2 using the internal pull-up resistor
A timer will be used to toggle P1.2.
A 20K? potentiometer is connected (as a voltage divider) to analog input 0 (A0).
>Draw a circuit which matches the above description. Calculations or justification should be shown for the resistors chosen for the circuit.
>Write an Embedded C function to setup the pins, pull-up resistors, special function and analog input registers: (Hint: The following registers should be modified: PxDIR, PxOUT, PxREN, ADC10AE0, PxSEL)
>Explain why a resistor is used when interfacing each LED with the microcontroller. What is the purpose of this resistor?
>Explain why a resistor is used when interfacing each switch with the microcontroller. What is the purpose of this resistor?
>Assuming the 10-Bit ADC on the MSP430 is used, what would be the input voltage to the ADC if the value returned in the ADC10MEM register was 500 (assuming the analog full scale voltage is 1.6V)?
Solution:
The circuit should have DC-DC Converter with decoupling capacitor to convert the 5V Supply to 3.3V output for the MSP430 micro controller.
Two LEDs are connected for P1.2 and P1.3 ports in sinking arrangement as and it is also called active high configuration. when outpin pin is high, then LED is ON and OF,F if otherwise.
A dip switch is connected to P2.1 port with external pull up resistor and the current is limited by the pull up resistor and when switch is pressed and read low.
A dip switch is connected to P2.2 port with internal pull up resistor and the current is limited by the pull up resistor and when switch is pressed and read low. Pull-up resistors can be activated by setting bits in the PxREN registers in MSP430 microcontrollers provided that the pin is configured as an input.
20K potentiometer is connected to A0 analog input as shown below.
The embedded C function can be written as to define all peripherals as
void int_io();
void int_io()
{
P1DIR |=0X0C; //set P1.2 and P1.3 to set the control digital IO
data port as output port
P2DIR &=0X60; //Set P2.1 and P2.2 as input port- dipswitch
P2REN = |= 0x04; //toenable internal pull up for Port P2.2
P1SEL = 0x01; // tomake the P1.0 pin as anaog input
ADC10AE0 = 0x01; // Enable analog input on channel 0
}
The purpose of the resistor is to limit the acceptable current to flow through LED.
The purpose of the resistor is to restrict the flow the current through the resistor when switch is closed to minimize the power dissipation in the circuit.