Dmitri
Published

MSP430 Analog Gauge Control in C

Control an analog gauge using an MSP430 and some simple logic.

Full instructions provided1,372
MSP430 Analog Gauge Control in C

Things used in this project

Hardware components

MSP430 Microcontroller
Texas Instruments MSP430 Microcontroller
I used the MSP430G2553 but you can use almost any variant
×1
TI Launchpad
Debugger
×1
Analog gauge
×1

Story

Read more

Code

file_10921.txt

Plain text
#include <msp430.h>

void configureClocks();	//function prototype

void goDown();		//function prototype

void goUp();	//function prototype

const unsigned int maximumPWM = 249;

const unsigned int maximumDelay = 10000;

const float multiplicationFactor = 0.004; //(10000 / (maximumPWM + 1)) / 10000

unsigned int x;

float percentagePWM;

volatile unsigned int i;

volatile unsigned int j;

file_10922.txt

Plain text
int main(void) {

	

	WDTCTL = WDTPW | WDTHOLD;		// Stop watchdog timer

	P1DIR |= 0x01;						 // Set P1.0 to output direction

	configureClocks();         // Call configureClocks function

	

file_10924.txt

Plain text
 void configureClocks()

 {

 BCSCTL1 = CALBC1_16MHZ;  // Set system DCO to 16MHz

 DCOCTL = CALDCO_16MHZ;//0xCD;

 }

file_10923.txt

Plain text
for(;;){		// do this forever

	goDown(); // function to make a movement from 0-100

	goUp();  // function to make a movement from 100-0

}

file_10925.txt

Plain text
void goDown() {

for(x = 1; x < maximumPWM; x++ ) {

	percentagePWM = 1 - (multiplicationFactor * x);

	j = maximumDelay * percentagePWM; 	//sw delay for off cycle

	i = maximumDelay - (maximumDelay * percentagePWM);	//sw delay for on cycle

	P1OUT = 0x01;			//Turn on P1.0

	do

	j--;

	while(j != 0);

	P1OUT ^= 0x01;	// Toggle P1.0 using exclusive-OR

	do

	i--;

	while(i != 0);

}

//return 0;

}

Credits

Dmitri

Dmitri

2 projects • 4 followers

Comments