Presentation is loading. Please wait.

Presentation is loading. Please wait.

UBI >> Contents Chapter 7 Timers Laboratories MSP430 Teaching Materials Texas Instruments Incorporated University of Beira Interior (PT) Pedro Dinis Gaspar,

Similar presentations


Presentation on theme: "UBI >> Contents Chapter 7 Timers Laboratories MSP430 Teaching Materials Texas Instruments Incorporated University of Beira Interior (PT) Pedro Dinis Gaspar,"— Presentation transcript:

1 UBI >> Contents Chapter 7 Timers Laboratories MSP430 Teaching Materials Texas Instruments Incorporated University of Beira Interior (PT) Pedro Dinis Gaspar, António Espírito Santo, Bruno Ribeiro, Humberto Santos University of Beira Interior, Electromechanical Engineering Department www.msp430.ubi.pt Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt

2 UBI >> Contents 2 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Contents  Laboratory 3: Use of timers: Laboratory 3: Use of timers  Lab3A_1: Memory clock with Basic Timer1 Lab3A_1: Memory clock with Basic Timer1  Lab3A_2: Real-Time Clock With Basic Timer1 Lab3A_2: Real-Time Clock With Basic Timer1  Lab3B: Memory Clock with Timer_A Lab3B: Memory Clock with Timer_A  Lab3C: Buzzer tone generator Lab3C: Buzzer tone generator  Lab3D: Frequency measurement Lab3D: Frequency measurement

3 UBI >> Contents 3 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Laboratory 3: Use of Timers  This hands-on laboratory consists of configuring the LCD_A controller of the MSP430FG41618 device of the Experimenter’s board to display a message on the liquid crystal display (LCD);  Like the previous exercise (Lab2), this one is composed of a series of sub-tasks. This laboratory has been developed for the Code Composer Essentials v3 only;  The Labs included in this chapter cover: Lab3A_1: Memory clock with Basic Timer1; Lab3A_2: Real Time Clock With Basic Timer1; Lab3B: Memory Clock with Timer_A; Lab3C: Buzzer; Lab3D: Frequency detection.

4 UBI >> Contents 4 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab3A_1: Memory clock with Basic Timer1  Overview:  This laboratory implements a memory clock using the features supported by Timer1;  The clock is updated once every second by the Basic Timer1 interrupt service routine (ISR);  This procedure also performs the switching of LED1;  In order to evaluate the execution time of the routine, LED2 is turned on during the execution of the ISR;  At the end of the execution of the ISR, the device goes into a low power mode, until the new interrupt wakes it again.

5 UBI >> Contents 5 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab3A_1: Memory clock with Basic Timer1  A. Resources:  Basic Timer1 generates an interrupt once every second;  The ISR is required to update the clock stored in memory;  Additionally, it must refresh the LCD.  The system resources used by this application are: Basic Timer1; I/O ports; LCD; Interrupts; Low power modes.

6 UBI >> Contents 6 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab3A_1: Memory clock with Basic Timer1  B. Software application organization:  The first task is to disable the Watchdog Timer;  All the resources needed for the LCD are configured;  The required source code is provided;  Once the LCD has been configured, it is cleared by the execution of the routine LCD_all_off();  The memory clock consists of three global variables of the type unsigned char: Hour; Min; Sec. These variables are initialized with zeros.

7 UBI >> Contents 7 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab3A_1: Memory clock with Basic Timer1  B. Software application organization (continued):  The LCD is refreshed at start up to preset the clock initial value;  LED1 provides an indication of Basic Timer1 ISR execution;  LED2 state switches whenever the Basic Timer1 ISR is executed;  The Basic Timer1 is set to generate an interrupt once every second.

8 UBI >> Contents 8 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab3A_1: Memory clock with Basic Timer1  B. Software application organization (continued):  The routine main() ends with the global interrupts enable and puts the device into low power mode, awaiting the next interrupt;  The Basic Timer1 ISR begins by activating LED2, indicating the beginning of the routine execution and then switches the state of LED1;  The counters are updated in cascade and their contents updated on the LCD, through the routines LCD_sec(), LCD_min() and LCD_hour();  The routine ends by switching the state of the clock separation characters. Finally, LED2 is turned off.

9 UBI >> Contents 9 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab3A_1: Memory clock with Basic Timer1  C. System configuration:  Disabling the Watchdog Timer: This peripheral is configured by the WDTCTL register. It is access protected by a password. What is the value to write to disabled it? WDTCTL = _______________;  FLL+ configuration: A 32768 Hz crystal is connected to the oscillator LFXT1. In order to select the internal capacitors, what is the value to write to the FLL_CTL0 configuration register in order to select 8 pF capacitors? FLL_CTL0 |= ____________;

10 UBI >> Contents 10 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab3A_1: Memory clock with Basic Timer1  C. System configuration (continued):  FLL+ configuration: Based on the values set in the previous step, what are the frequencies of each of the clock signals? ACLK = _________________ MCLK = _________________ SMCLK = ________________

11 UBI >> Contents 11 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab3A_1: Memory clock with Basic Timer1  C. System configuration (continued):  LED ports configuration: LED1 and LED2 are connected to ports P2.2 and P2.1 respectively; How should the bits related to these ports be configured in order to have digital output functions? P2DIR = _________________; How the should the P1OUT register be configured so that the application starts with LED1 on and LED2 off? P1OUT = _________________;

12 UBI >> Contents 12 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab3A_1: Memory clock with Basic Timer1  C. System configuration (continued):  Basic Timer1 configuration: Generates an interrupt once every second. It uses two counters in series, so that the input of the BTCNT2 counter is the output of the BTCNT1 (ACLK = 32768 Hz) counter divided by 256; If the output of the BTCNT2 counter is divided by 128, what is the time period generated by the Basic Timer1 interrupt? _________ Configure the registers: BTCTL = ________________; IE2 = __________________;

13 UBI >> Contents 13 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab3A_1: Memory clock with Basic Timer1  C. System configuration (continued):  Low power modes: The task simply updates the counters and refreshes the LCD contents periodically; It is possible to obtain an energy efficient operation. Which low power mode should be used?_____________ Which system clocks are activated in the low power mode selected? _____________________

14 UBI >> Contents 14 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab3A_1: Memory clock with Basic Timer1  D. Analysis of operation:  Project file LAB2A_1_student.c;  Solution file: LAB2A_1_solution.c;  One of these files should be used in the implementation of the project. After it has been compiled, debug the project.  System clocks inspection: The MCLK, SMCLK and ACLK system clocks are available at ports P1.1, P1.4 and P1.5 respectively.

15 UBI >> Contents 15 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab3A_1: Memory clock with Basic Timer1  D. Analysis of operation (continued):  System clocks inspection: Using the Registers view, set the bits 1, 4 and 5 of P1SEL and P1DIR registers to select the secondary function of the ports configured as outputs; The clock signals on these ports can be monitored using an oscilloscope; What are the values of each of the system clocks? ACLK: ________________ SMCLK: _______________ MCLK: ________________

16 UBI >> Contents 16 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab3A_1: Memory clock with Basic Timer1  D. Analysis of operation (continued):  ISR execution time:  The Basic Timer1 ISR execution time is fundamental to energy conservation in order to extend the battery life of the system;  The routine execution time can be measured by connecting an oscilloscope to port P2.1, that controls LED2;  This output is available on pin 2 of Header H4.

17 UBI >> Contents 17 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab3A_1: Memory clock with Basic Timer1  D. Analysis of operation (continued):  ISR execution time:  The execution time of this routine varies with the number of counter updates and related updates of the LCD;  What are the values of time measured for each of the values and what are their frequencies? Sec update: ______ with a time period of ______ Sec and min update: ______ with a time period of ______ LCD fields update: ______ with a time period of ______

18 UBI >> Contents 18 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab3A_1: Memory clock with Basic Timer1  D. Analysis of operation (continued):  Measurement of electrical current drawn:  The energy consumption was mentioned in the previous point;  The electrical power required by the operation of the system is measured by replacing in the Header PWR1 the jumper by a milli-ammeter, which indicates the electric current taken when the device is in operation;  What is the value measured? __________

19 UBI >> Contents 19 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab3A_2: Real Time Clock With Basic Timer1  Overview:  The Real Time Clock (RTC) has a 32-bit counter to automatically control a calendar clock;  This peripheral can be found in devices of the MSP430FG461x family;  The application developed in the previous laboratory is now modified to use this module.

20 UBI >> Contents 20 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab3A_2: Real Time Clock With Basic Timer1  A. Resources:  This application is based on the same resources used in the previous laboratory;  In addition, there are a RTC peripheral and two switches, SW1 and SW2;  The RTC module updates the clock calendar automatically;  The push buttons change information displayed on the LCD between clock and calendar.

21 UBI >> Contents 21 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab3A_2: Real Time Clock With Basic Timer1  B. Software application organization:  The organization of the software is identical to that of LAB3A_1 lab;  The Basic Timer1, LCD and LEDs continue to perform the same functions;  They are to be configured in a similar way, but with the following changes:  The configurations for RTC and switches SW1 and SW2 are added to the routine main().

22 UBI >> Contents 22 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab3A_2: Real Time Clock With Basic Timer1  B. Software application organization (continued):  The memory addresses corresponding to the clock calendar values are initialized with the default values of: zero hours, zero minutes and zero seconds, on August 9, 2008;  The RTC is then activated in calendar mode, with the interrupt disabled. This mode controls the operation of Basic Timer1;  Switches SW1 and SW2 are connected to microcontroller ports P1.0 and P1.1 respectively;  These ports are configured as inputs and their interrupts activated on a transition from high-to-low.

23 UBI >> Contents 23 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab3A_2: Real Time Clock With Basic Timer1  C. System configuration:  Real Time Clock configuration: The RTC is configured in calendar mode and is enabled; The counting registers hold the values of seconds, minutes, hours, days, day of the week, the day of the month, month and year; The values are stored in the counting registers in BCD, so as speed up the writing of data to the LCD.

24 UBI >> Contents 24 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab3A_2: Real Time Clock With Basic Timer1  C. System configuration (continued):  Real Time Clock configuration: The interrupt for this peripheral should be disabled (disable the Basic Timer1 interrupt); Given this objective, what value should be configured in the following register? RTCCTL = ____________________;

25 UBI >> Contents 25 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab3A_2: Real Time Clock With Basic Timer1  C. System configuration (continued):  Real Time Clock configuration: The RTC operation in calendar mode automatically configures some of the Basic Timer1 features: The content of the BTSSEL, BTHOLD and BTDIV bits of the BTCNT register are ignored; The BTCNT1 and BTCNT2 counters work in cascade; The clock source of the BTCNT1 counter is the ACLK clock signal;

26 UBI >> Contents 26 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab3A_2: Real Time Clock With Basic Timer1  C. System configuration (continued):  Real Time Clock configuration: The output of the BTCNT1.Q7 counter is selected as the input of the BTCNT2 counter (frequency: ACLK/256); The RTC uses the BTCNT2.Q6 output as the clock source (frequency: ACLK/32768).  Basic Timer1 configuration: Automatically configured with the calendar mode RTC; To enable the interrupt once each 0.5 seconds, what is the value to write to the following register? BTCNT = ________________;

27 UBI >> Contents 27 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab3A_2: Real Time Clock With Basic Timer1  C. System configuration (continued):  Ports P1.0 and P1.1 configuration: The switches SW1 and SW2 are connected to ports P1.0 and P1.1 respectively; How should the following registers be configured in order to set just the bits which are used as digital inputs with high-to-low transition interrupts? P1SEL &= _______________; P1DIR &= _______________; P1IFG = _______________; P1IES &= _______________; P1IE |= ________________;

28 UBI >> Contents 28 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab3A_2: Real Time Clock With Basic Timer1  D. Analysis of operation:  Complete the blank spaces in the file LAB2A_2_student.c;  Solution file: LAB2A_2_solution.c;  One of these files should be included in the building of the project. After it has been compiled, debug the project.  ISR execution time: Perform similar procedures to those described in Lab3A_1 to measure the ISR execution time. What is the value measured? LCD refresh: ______

29 UBI >> Contents 29 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab3A_2: Real Time Clock With Basic Timer1  D. Analysis of operation (continued):  ISR execution time: The LCD writing routines have been changed; Taking advantage of the fact that data is stored in BCD format, the division operation is not required, resulting in the reduction of execution time of the Basic Timer1 ISR; Is the processing time required to refresh the LCD is the same? _____

30 UBI >> Contents 30 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab3A_2: Real Time Clock With Basic Timer1  D. Analysis of operation (continued):  Measurement of Electrical current drawn: Using a similar method to that described at the corresponding point of Lab3A_1, measure the value of current drawn by the device. What is the value measured? __________

31 UBI >> Contents 31 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab3B: Memory Clock with Timer_A  Overview:  The objective of the laboratory is to build a memory clock similar to the one that was developed using the Basic Timer1 in Lab3A_1;  The Timer_A is configured to generate an interrupt once every 100 msec;  The ISR manages of the memory clock;  LED1 and LED2 are used to monitor the operation of the system state.

32 UBI >> Contents 32 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab3B: Memory Clock with Timer_A  A. Resources:  This application makes use of Timer_A to generate an interrupt when the value in the TACCR0 unit is reached;  The ISR updates the contents of the memory clock variables;  LED1 is used to monitor system operation, switching state whenever Timer_A ISR runs;  LED2 can be used to monitor the ISR execution time. The contents of the LCD is updated once every interrupt;  When the ISR finishes, the device returns to low power mode.

33 UBI >> Contents 33 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab3B: Memory Clock with Timer_A  A. Resources (continued):  The system resources used by this application are: –Timer_A; –I/O ports; –LCD; –Interrupts; –Low power modes.  The default configuration of the FLL+ is used;  All the clock signals required for the operation of the components of the device take their default values.

34 UBI >> Contents 34 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab3B: Memory Clock with Timer_A  B. Software application organization:  The first task is to disable the Watchdog Timer;  All the resources needed for the LCD are configured;  This code is given;  Once configured, the LCD is cleared by the execution of the routine LCD_all_off().

35 UBI >> Contents 35 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab3B: Memory Clock with Timer_A  B. Software application organization (continued):  The memory clock consists of a three global variables of type unsigned char: Min; Sec; Msec; These variables are initialized with zeros.  The LCD is refreshed at startup to preset the clock to its initial value;  LED2 is used as an indicator of Timer_A ISR execution;  LED1 state switches whenever the Timer_A ISR is executed.

36 UBI >> Contents 36 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab3B: Memory Clock with Timer_A  B. Software application organization (continued):  Timer A is generates an interrupt once every 100 msec;  The routine main() ends with global interrupts enable and goes to a low power mode;  Timer A ISR begins by activating the LED2 (routine execution init) and then switches the LED1 state;  The counters are updated in cascade and their contents updated on the LCD, through routines LCD_msec(), LCD_sec() and LCD_min();  The routine ends by switching the state of the clock separation characters and switching off LED2.

37 UBI >> Contents 37 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab3B: Memory Clock with Timer_A  C. System configuration:  Disable the Watchdog Timer: The Watchdog Timer is configured as in the above examples.  FLL+ configuration: FLL+ is configured as in the above examples.  LED ports configuration: LED ports are configured as in the above examples.

38 UBI >> Contents 38 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab3B: Memory Clock with Timer_A  C. System configuration (continued):  Timer_A configuration: Timer_A is configured to count until it reaches the value contained in the TACCR0 capture/compare unit; An interrupt is generated when it reaches that value. Which is the interrupt vector to use? ____________ Timer_A clock signal is the ACLK without division. What is the value to write in the configuration register? TACTL = _____________;

39 UBI >> Contents 39 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab3B: Memory Clock with Timer_A  C. System configuration (continued):  Timer_A configuration: The TACCR0 capture/compare unit establishes the Timer_A counting range; For a 100 msec response, what is the value to write in the following register? TACCR0 = ____________; The interrupt is configured in the TACCR0 capture/compare unit. What is the value to write to the following register: CCTL0 = _____________;

40 UBI >> Contents 40 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab3B: Memory Clock with Timer_A  D. Operation analysis:  Source code file: LAB2B_student.c;  Solution file: LAB2B_solution.c;  One of these files should be included in the building of the project. After the project has been compiled, debug it.  ISR execution time: Using a similar approach to that described in laboratory Lab3A, measure the ISR execution time; What is the value determined? LCD refresh rate: ______

41 UBI >> Contents 41 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab3B: Memory Clock with Timer_A  D. Operation analysis (continued):  Measurement of electrical current drawn: Using a procedure similar to that described in the corresponding point of Lab3A_1, measure the value of current drawn by the device. What is the value measured? __________

42 UBI >> Contents 42 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab3C: Buzzer tone generator  Overview:  The purpose of this laboratory is to build a sound generator using Timer B;  The PWM signal produced by this peripheral drives the buzzer, producing a sequence of notes at regular time intervals, stored in memory;  At the same time, LED1 and LED2 switch states alternately;  The sound volume produced by the buzzer can be controlled through switches SW1 and SW2.

43 UBI >> Contents 43 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab3C: Buzzer tone generator  A. Resources:  This application requires the production of specific frequency signals corresponding to musical notes;  For each frequency the duty-cycle can be modified in order to control the volume of sound produced;  This task is carried out using Timer_B and one of its compare units;  The buzzer is operated by Port P3.5 pin configured to work in its special function of TB4 output compare unit;  This output corresponds to the TBCCR4 output compare unit.

44 UBI >> Contents 44 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab3C: Buzzer tone generator  A. Resources (continued):  The push button switches SW1 and SW2 are connected to ports P1.0 and P1.1 respectively;  An interrupt is generated when either one of these buttons is activated;  The duty cycle of the frequency is modified in response;  The Basic Timer1 is configured to generate an interrupt once every second. The interrupt service routine updates the musical notes produced by the buzzer. The notes are stored in an array;  LED1 and LED2 ports are controlled by P2.2 and P2.1 respectively, and their state is switched alternately once every second.

45 UBI >> Contents 45 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab3C: Buzzer tone generator  B. Software application organization:  The application consists of the routine main() to configure all system resources, before entering into standby mode where it waits for one of two interrupts;  This routine starts by disabling the watchdog and starting the module FLL+ to produce the desired clock signals for the SMCLK and MCLK;  Then, Basic Timer1 and Timer_B are configured.  The ports connected to the LEDs, switches and buzzer are then initialized;  Finally, the interrupts are activated, and the application waits for the execution of one of two interrupts.

46 UBI >> Contents 46 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab3C: Buzzer tone generator  B. Software application organization (continued):  The Basic Timer1 interrupt is executed at a frequency of once every second;  When this interrupt is generated, it begins by switching the state of LED1 and LED2;  Afterwards, it accesses the memory to obtain the next musical note to be processed;  The routine ends with memory pointer management.  The Port 1 ISR begins by evaluating the source of the interrupt ;  The sound volume is reduced or increased by button presses of SW1 and SW2 respectively.

47 UBI >> Contents 47 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab3C: Buzzer tone generator  C. System configuration:  Timer_B: It is the responsibility of Timer_B to produce the PWM signal that activates the Buzzer; Timer B counts until the value contained in TBCCR0 register is reached; It does not generate an interrupt, and must be sourced by SMCLK clock signal. What is the value to write to this configuration register? TBCTL = _____________;

48 UBI >> Contents 48 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab3C: Buzzer tone generator  C. System configuration (continued):  Timer_B: Each PWM signal produced by Timer_B corresponds to a musical note provided in a relationship table between the frequency and the musical note.

49 UBI >> Contents 49 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab3C: Buzzer tone generator  C. System configuration (continued):  Timer_B: Timer_B has a 7.995392 MHz frequency clock input. What is the value to write in the TBCCR0 register in order to generate the desired frequencies?

50 UBI >> Contents 50 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab3C: Buzzer tone generator  C. System configuration (cont):  Timer_B: The TBCCR4 compare unit is used to produce the PWM signal; The set/reset compare mode is used; What is the value to write in the configuration register? TBCCTL4 = _______________; The volume control consists of varying the PWM signal duty-cycle. Initially, its default value is 50%; What is the configuration to write in the register? TBCCR4 = ________________;

51 UBI >> Contents 51 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab3C: Buzzer tone generator  C. System configuration (continued):  Basic Timer1: The Basic Timer1 generates an interrupt once every second; It uses the two counters in series, with BTCNT2 counter input selected as BTCNT1 counter output divided by 256. The BTCNT1 counter input is the ACLK clock signal with a frequency of 32768 Hz. If BTCNT2 counter selected output is divided by 128, what is the time period required by the Basic Timer1 interrupt? _________ What are the values to write in configuration registers? BTCTL = __________________; IE2 = ____________________;

52 UBI >> Contents 52 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab3C: Buzzer tone generator  C. System configuration (continued):  I/O Ports: Three ports are used by this application; In port P1, bit P1.0 and P1.2 are used to activate the ISR whenever the buttons SW1 and SW2 are activated. How should just the bits related to these ports be configured in order to have digital input functions with high-to-low transition interrupts? P1SEL &= ________________; P1DIR &= ________________; P1IFG = _________________; P1IES &= ________________; P1IE |= _________________;

53 UBI >> Contents 53 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab3C: Buzzer tone generator  C. System configuration (continued):  I/O Ports: LED1 and LED2 are connected to ports P2.2 and P2.1 respectively; How should just the bits related to these ports be configured in order to have digital output functions? P2DIR = ___________________; Configure the P2OUT register in order to initialize the application with LED1 on and LED2 off. P2OUT = ___________________;

54 UBI >> Contents 54 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab3C: Buzzer tone generator  C. System configuration (continued):  FLL+ configuration: This module uses the 32768 Hz frequency crystal to produce a 7.995392 MHz frequency at the SMCLK and MCLK clock signals; What are the values to write in the following configuration registers? FLL_CTL0 |= ________________; SCFI0 |= ___________________; SCFQCTL = __________________;

55 UBI >> Contents 55 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab3C: Buzzer tone generator  D. Analysis of operation:  System clocks inspection: The MCLK, SMCLK and ACLK system clocks are connected at to ports P1.1, P1.4 and P1.5 respectively; Using the Registers view, set bits 1, 4 and 5 of P1SEL and P1DIR registers to select the secondary function of these ports configured as outputs; By connecting an oscilloscope onto these lines, it is possible to monitor the clock signals; What are the values measured for the system clocks? ACLK: _____________________ SMCLK: ____________________ MCLK: _____________________

56 UBI >> Contents 56 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab3C: Buzzer tone generator  D. Analysis of operation (continued):  TBCCR4 unit output frequency: With the help of the oscilloscope it is possible to evaluate the performance of the application; Alternatively, it is possible to listen to the sound produced; By removing jumper JP1 and connecting an oscilloscope probe at this point, it is possible to monitor the PWM signal produced by the microcontroller; The duty-cycle can be reduced or increased by activating the push button switches SW1 and SW2 respectively.

57 UBI >> Contents 57 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab3C: Buzzer tone generator  D. Analysis of operation (continued):  Port P1 interrupt source decoding: All Port P1 interrupt lines share the same interrupt vector; Decoding is done through the P1IFG register; This process can be monitored by entering a breakpoint at the first line of code of the ISR; Execute the application; The execution of the application is suspended at this breakpoint when either button SW1 or SW2 is pressed; Press button SW1 or SW2 then run the lines of code step-by-step and observe how the registers change.

58 UBI >> Contents 58 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab3C: Buzzer tone generator  D. Analysis of operation (continued):  Measurement of electrical current drawn: Using a procedure similar to that described at the corresponding point of Lab3A_1, measure the value of current drawn by the device. What is the value measured? __________

59 UBI >> Contents 59 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab3D: Frequency measurement  Overview:  This laboratory implements an application designed to measure the frequency of a PWM signal;  The microcontroller can be used to generate a PWM signal based on the frequencies stored in a file, if a signal generator is not available;  The frequencies generated are read and updated with a fixed time period using the features of CCE;  The measured value [Hz] is shown on the LCD.

60 UBI >> Contents 60 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab3D: Frequency measurement  A. Resources:  The module FLL+ is configured to 7.995392 MHz frequency for the MCLK and SMCLK clock signals;  The program generates a PWM signal, with a frequency of 200 Hz and a duty cycle of 50%.The PWM signal frequency can be read from a file using a breakpoint (Lab3d_breakpoint.bkpt);  This function is performed by Timer B, using the compare unit to generate the PWM signal.  The time period between two consecutive PWM signal low- to-high transitions is measured by Timer_A;  The capture unit of Timer_A is configured to acquire the contents of Timer A counting register when a low-to-high transition of the PWM signal is detected.

61 UBI >> Contents 61 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab3D: Frequency measurement  A. Resources (continued):  The Basic Timer1 generates an interrupt once every second;  The ISR updates the frequency of the PWM signal generated by Timer_B;  A breakpoint associated with this ISR execution allows the value of the frequency to be read from a file;  The ports of the microcontroller are configured so that the PWM signal generated by Timer_B through the TBCCR4 compare unit (Port P3.5/TB4 - Header 7 pin 6) can be connected to the Port P1.2/TA1 (Header H2 pin 3) of the Timer_A TACCR1 capture unit;  These pins must be connected together;

62 UBI >> Contents 62 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab3D: Frequency measurement  A. Resources (continued):  Ports P2.1 and P2.2 are used to monitor the state of LED2 and LED1, respectively;  The resources used by the application are: –Timer_A; –Timer_B; –Basic Timer1; –I/O ports; –FLL+; –Interrupts.

63 UBI >> Contents 63 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab3D: Frequency measurement  B. Software application organization:  The software structure allows various tasks to be performed at the same time;  The routine main() is responsible for configuring all the resources used by the application;  Once started, the application enables all the interrupts and waits for an interrupt request;  Two separate routines service the possible interrupts: TimerA1_ISR(): services interrupts generated by Timer A overflow and the TACCR1 capture unit; basic_timer_ISR(): services the interrupt produced by the Basic Timer1 once every second.

64 UBI >> Contents 64 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab3D: Frequency measurement  C. System configuration:  Basic Timer1: The Basic Timer1 generates an interrupt once every second; Use the two counters in series, with BTCNT2 counter input driven from the output of BTCNT1 counter divided by 256; The BTCNT1 counter input is the ACLK clock (32768 Hz) If BTCNT2 counter selected output is divided by 128, what is the time period of the Basic Timer1 interrupt? _________ What are the values to write in configuration registers? BTCTL = ________________; IE2 = __________________;

65 UBI >> Contents 65 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab3D: Frequency measurement  C. System configuration (continued):  Timer_B: The TBCCR4 compare unit is used to generate the PWM signal; The set/reset compare mode is used; What is the value to write in the configuration register? TBCCTL4 = ______________; The TB4 PWM output signal has a frequency X, with a 50% duty-cycle; The SMCLK clock signal is used as input of Timer_B.

66 UBI >> Contents 66 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab3D: Frequency measurement  C. System configuration (continued):  Timer_B: What is the value to write to the registers? TBCCR0 = _______________; TBCCR4 = _______________; What the highest and lowest generated frequency? –Maximum frequency value: ____________ –Minimum frequency value: _____________

67 UBI >> Contents 67 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab3D: Frequency measurement  C. System configuration (continued):  Timer_A: Timer_A is sourced by the SMCLK clock signal; It counts to the value 0xFFFF, in continuous mode; An interrupt is generated when the TAR counter overflows; What is the value to write in its configuration register? TACTL = _________________;

68 UBI >> Contents 68 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab3D: Frequency measurement  C. System configuration (continued):  Timer_A: The capture unit compares the TAR register value to the TACCR1 register and detects a low-to-high transition at the TA1 input; What is the value to write in the configuration register? TACCTL1 = _______________; Determine the maximum and minimum frequency values detected;

69 UBI >> Contents 69 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab3D: Frequency measurement  C. System configuration (continued):  Timer_A: Note that these values do not take into account the execution time of the application; The PWM signals should be applied at frequencies far below the maximum value determined: –Maximum frequency value: ____________ –Minimum frequency value: _____________ The TACCR1 capture unit is configured to generate an interrupt when it detects a low-to-high transition; What is the value to write in the configuration register? TACCTL1 = _____________;

70 UBI >> Contents 70 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab3D: Frequency measurement  C. System configuration (continued):  Ports P3.5/TB4 and P1.2/TA1 configuration: These ports perform special functions; Port P3.5 is configured as an output selected for the special function TB4, with the values: P3SEL = _______________; P3DIR = _______________; Port P1.2 is configured as an input, selected for the special function TA1, with the values: P1SEL = _______________; P1DIR = _______________;

71 UBI >> Contents 71 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab3D: Frequency measurement  D. Analysis of operation:  Run the application using the frequency generator based on Timer_B: Without a frequency generator, the Timer_B generates a PWM signal at the TBCCR4 unit output that can be feedback to Timer_A TACCR1 capture unit input; These two pins must therefore be connected together; By default, the PWM signal frequency is 200 Hz; Add a breakpoint at line 223 of code, which is for Basic Timer1 ISR and modify this value. TBCCR0 =7995392/read_data;

72 UBI >> Contents 72 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab3D: Frequency measurement  D. Analysis of operation (continued):  Run the application using a frequency generator: The operation of the application can be measured using a frequency generator; The generator should generate a PWM signal with voltage and frequency values compatible with the input range of the device (2.5 to 3.3 V).  Monitor the measured frequency: The PWM signal applied to the TA1 input can be monitored using an oscilloscope connected to pin 3 of Header 2; Perform this task and confirm the values present on the LCD.

73 UBI >> Contents 73 Copyright 2009 Texas Instruments All Rights Reserved www.msp430.ubi.pt Lab3D: Frequency measurement  D. Analysis of operation (continued):  Measurement of electrical current drawn: Follow the procedure described in previous laboratories to measure the current. What is the value measured? __________


Download ppt "UBI >> Contents Chapter 7 Timers Laboratories MSP430 Teaching Materials Texas Instruments Incorporated University of Beira Interior (PT) Pedro Dinis Gaspar,"

Similar presentations


Ads by Google