Quantcast
Channel: Forums - Recent Threads
Viewing all articles
Browse latest Browse all 262198

MSP430G2553: How to use this timer class with a button?

$
0
0

Part Number:MSP430G2553

Hello! I am currently taking a class in programming embedded systems and we recently got this device to do our labs/tasks on.

This week's task is to toggle the red light on and off using the Button (BIT3) and also to write the code in seperate files using header files and classes. 

Anyway, I have got the functonality to work, as in button press --> on, press again --> off. My problem is, I don't understand how to use this timer.c class that we were given. I suppose it's meant to be used in a way so that the debounce problem is fixed?

Here is the code for timer.c

#include "project.h"
#include "led.h"

#include "timer.h"

#define DIVIDER 8
#define TMRC (DCO_FREQ / DIVIDER / 1000 * TIMER_INTERVAL)

static tWord tickCount=0;

void Timer_Init() {

        BCSCTL1 = CALBC1_16MHZ;
        DCOCTL = CALDCO_16MHZ;
        BCSCTL2 = 0x0 ; // MCLK clock source DCOCLK, MCLK divider 1, SMCLK source DCOCLK, SMCLK divider 1

        // Set up interrupts and timer 0

        // Enable interrupts on timer
        CCTL0 = CCIE;

        // Use clock SMCLK, UP counting, divided of 8
        TACTL = TASSEL_2 + MC_1 + ID_3;
       
        // Set compare value
        CCR0 = TMRC;
}

__attribute__((interrupt(TIMER0_A0_VECTOR))) void Timer_A(void) { 
timer_run(); 
} 

tWord getTick() {return tickCount;}

timer_run() {
	tickCount++;
	Led_Update();
}

tWord == unsigned int

#define TMRC (DCO_FREQ / DIVIDER / 1000 * TIMER_INTERVAL) <-- In this lie, nothing is defined and I don't even understand what DCO_FREQ is? TIMER_INTERVAL I think has to be set by the main function which I actually do.

Led_Update is written by me:

void Led_Update() {
	if(status==LED_STAT_ON) {
		RED_LED_PORT |= RED_LED_PIN;
	}
	else {
		RED_LED_PORT &= ~RED_LED_PIN;
	}
}

The status variable changes on button press.

Can anyone give me some tips on how to use the timer class? I also obviously use __enable_interrupt(); in my main class. I have noticed the Timer_A interrupt method runs quite frequently if I manually set CCR0 = 10000; for ex....

Thanks!


Viewing all articles
Browse latest Browse all 262198

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>