Course Hero Logo

Lab4_AP.docx - EEL 4742C Embedded Systems Name: Alejandro...

Course Hero uses AI to attempt to automatically extract content from documents to surface to you and others so you can study better, e.g., in search results, to enrich docs, and more. This preview shows page 1 - 3 out of 7 pages.

EEL 4742C Embedded SystemsName: Alejandro PorcarLab 4: Interrupts & Low-Power ModesIntroductionIn this Lab, we learned how to utilize the timer module in our MSP430 board to create timingevents while being in low-power mode at the same time. This will come to be very useful in thefuture since low-power mode is one of the key features of some embedded systems.4.1Continuous Mode with Interrupt// Timer_A continuous mode, with interrupt, flashes LEDs#include<msp430fr6989.h>#defineredLED BIT0// Red LED at P1.0#definegreenLED BIT7// Green LED at P9.7// Configures ACLK to 32 KHz crystalvoidconfig_ACLK_to_32KHz_crystal() {// By default, ACLK runs on LFMODCLK at 5MHz/128 = 39 KHz// Reroute pins to LFXIN/LFXOUT functionalityPJSEL1 &= ~BIT4;PJSEL0 |= BIT4;// Wait until the oscillator fault flags remain clearedCSCTL0 = CSKEY;// Unlock CS registersdo{CSCTL5 &= ~LFXTOFFG;// Local fault flagSFRIFG1 &= ~OFIFG;// Global fault flag}while((CSCTL5 & LFXTOFFG) != 0);CSCTL0_H = 0;// Lock CS registersreturn;}voidmain(void) {WDTCTL = WDTPW | WDTHOLD;// Stop the WatchdogtimerPM5CTL0 &= ~LOCKLPM5;// Enable the GPIO pinsP1DIR |= redLED;// Direct pin as outputP9DIR |= greenLED;// Direct pin as outputP1OUT &= ~redLED;// Turn LED OffP9OUT &= ~greenLED;// Turn LED Off// Configure ACLK to the 32 KHz crystalconfig_ACLK_to_32KHz_crystal();// Timer_A configuration (fill the line below)// Use ACLK, divide by 1, continuous mode, TAR cleared, enable interrupt forrollback-to-zero event
TA0CTL = TASSEL_1 | ID_0 | MC_2 | TACLR |TAIE;// Ensure the flag is cleared at the startTA0CTL &= ~TAIFG;// Enable the global interrupt bit (call an intrinsic function)_enable_interrupts();// Infinite loop... the code waits here between interruptsfor(;;) {}}//******* Writing the ISR *******#pragmavector = TIMER0_A1_VECTOR// Link the ISR to the vector__interruptvoidT0A1_ISR() {// Toggle both LEDsP1OUT ^= redLED;P9OUT ^= greenLED;// Clear the TAIFG flagTA0CTL &= ~TAIFG;}

Upload your study docs or become a

Course Hero member to access this document

Upload your study docs or become a

Course Hero member to access this document

End of preview. Want to read all 7 pages?

Upload your study docs or become a

Course Hero member to access this document

Term
Spring
Professor
NoProfessor
Tags

Newly uploaded documents

Show More

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture