Month: April 2013

LM4f120: Using “buttons.h” for inbuilt buttons.

Last few days I spent a lot of time with the LM4F120 board just to get familiarized with the Stellarisware APIs. There are some documents available with the software which gives a good picture on the behavior of those APIs. Since TI discontinued Stellarisware you can find these documents under Tivaware section in TI.com.

Following is the way to implement ‘button.h’ in your code. Here, I will be using inbuilt buttons to turn on and off the LEDs in the circuit.

Code:

#include "inc/hw_types.h"
#include "inc/hw_memmap.h"
#include "driverlib/sysctl.h"
#include "driverlib/gpio.h"
#include "drivers/buttons.h"

int main(void) {

unsigned char button_val;
unsigned char Delta;
unsigned char Rawstate;

SysCtlClockSet(SYSCTL_SYSDIV_5| SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN);

SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE , GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3);

ButtonsInit();

while(1){
SysCtlDelay(100000);

button_val = ButtonsPoll(&Delta, &Rawstate);

if(BUTTON_PRESSED(LEFT_BUTTON,button_val,Delta)){
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 0xFF);
}

if(BUTTON_PRESSED(RIGHT_BUTTON,button_val,Delta)){
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 0x00);
}
}

}

But unfortunately this code alone will not do the trick. You should strictly adhere to following steps in order to build this code. Otherwise you will receive “Unresolved variable …” errors.
(more…)

MSP430: Temperature stabilizer

It has been a while since I played with the MSP430G2 evaluation board. Recently one of my friends wanted me to build a temperature stabilizer for one of his projects. The requirement was to stabilize a water container at 50 Centigrades. I decided to use the MSP430 as it has the basic components needed for it. In this post I will be talking about the code I used in the MSP430.

I used MSP430G2553 micro controller to do all the processing,
I used LM35 temperature sensor to measure the temperature.

The application was straight forward. I had to connect the LM35 IC through the ADC of the MSP430 and process the signal.

Schematic:

Following is the connection diagram.

 060420131317

Logic:

Following is a state diagram of the problem.

060420131316

LM35:

According to the datasheet of the LM35 it works within 4V and 30V supply voltages. Since the MSP430 works at 3.3V I used a 9V battery to power up the LM35 IC. But the ground should be shared with the launchpad for this to work properly. It gives 10mV/C as the output in a linear scale.

Code:

The coding was done using the TIs code composer studio.

#include <MSP430.h>

/*
* main.c
*/

unsigned int value = 0;
unsigned int upperT = 180;
unsigned int lowerT = 160;

//The function to configure the ADC
void configureAdc(){
ADC10CTL0 = SREF_1 + ADC10SHT_0 + ADC10ON + ADC10IE + REFON;
ADC10CTL1 = INCH_5 + ADC10DIV_3;
ADC10AE0 |= BIT5;
}

// ADC10 interrupt service routine
#pragma vector=ADC10_VECTOR;

__interrupt void ADC10_ISR (void)
{
__bic_SR_register_on_exit(CPUOFF); // Return to active mode
}

int main(void) {
short flag = 1; //relay on
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer

BCSCTL1 = CALBC1_1MHZ; //Clock calibration
DCOCTL = CALDCO_1MHZ;
BCSCTL2 &= ~(DIVS_3);

P1DIR |= BIT0 + BIT6; //GPIO selection
P1SEL |= BIT5;

P1OUT &= ~(BIT0 + BIT6); //LEDx off

configureAdc();
__enable_interrupt();

P1OUT |= BIT6; //LED1 ON

while(1){
__delay_cycles(2000000); //delay 2sec
ADC10CTL0 |= ENC + ADC10SC; //Enable conversion
__bis_SR_register(CPUOFF + GIE); //Low power mode with enabled interrupts
value = ADC10MEM; //ADC conversion

if(flag == 1){ //When relay is on
if (value>=upperT){ //Wait until T = 53C
P1OUT &= ~(BIT0 + BIT6);
P1OUT |= BIT0;
flag = 0; //relay off //Turn off the relay
}
}
else if(flag==0){ //When relay is off
if (value<=lowerT){ //Wait until T = 47C
P1OUT &= ~(BIT0 + BIT6);
P1OUT |= BIT6;
flag = 1; //relay on //Turn on the relay
}

}

}

return 0;
}