Network and Systems Laboratory nslab.ee.ntu.edu.tw.

Slides:



Advertisements
Similar presentations
BASICS OF MSP430 & INTERFACING MICRO-SD CARD WITH IT.
Advertisements

Interrupts, Low Power Modes and Timer A (Chapters 6 & 8)
Chung-Ta King National Tsing Hua University
More fun with Timer/Counters
Lizard Labs Peripheral Reflex System
Chung-Ta King National Tsing Hua University
Network and Systems Laboratory nslab.ee.ntu.edu.tw 2010/12/31Wireless Sensor Network And Labs fall
ECE 447 Fall 2009 Lecture 9: TI MSP430 Interrupts & Low Power Modes.
Notes on the ez430-RF2500. Sources
Infineon Technologies Corp. June 99 1 HOT167-1 Version 2.0 F PWMmax = x 50ns = 78 kHz Pulse Width Modulation Unit (PWM) (20 MHz)  4 independent.
Timers and Interrupts Shivendu Bhushan Summer Camp ‘13.
CS4101 嵌入式系統概論 Timers and Clocks 金仲達教授 國立清華大學資訊工程學系 Materials from MSP430 Microcontroller Basics, John H. Davies, Newnes, 2008.
MSP Ultra-Low Power | High Integration | Easy-to-Use “How To” Series: Clock System.
Network and Systems Laboratory nslab.ee.ntu.edu.tw.
Chung-Ta King National Tsing Hua University
Timers. Range of timers Watchdog timer: Included in all devices (watchdog timer+). Its main function is to protect the system against malfunctions but.
Engineering 1040: Mechanisms & Electric Circuits Fall 2011 Introduction to Embedded Systems.
The 8051 Microcontroller architecture
LAB 7: WDT+ and Low-Power Optimization
T IMERS - 2. O UTPUT U NIT Each capture/compare block contains an output unit. The output unit is used to generate output signals such as PWM signals.
Network and Systems Laboratory nslab.ee.ntu.edu.tw.
ARM Timers.
System Clocks.
EE 446 Project Assignment Top Design Sensor Components Pin Assignment and Configuration Completed Physical Setup Project Tasks.
A Few Words From Dilbert
MSP430 Mixed Signal Microcontroller – Parte 2 Afonso Ferreira Miguel Source: slau056d – Texas instruments.
CPE 323 Introduction to Embedded Computer Systems: Watchdog Timer, Timer A Instructor: Dr Aleksandar Milenkovic Lecture Notes.
MCU: Interrupts and Timers Ganesh Pitchiah. What’s an MCU ?
ECE 447 Fall 2009 Lecture 10: TI MSP430 Timers and Capture Modes.
SIGMA-DELTA ADC SD16_A Sigma-Delta ADC Shruthi Sujendra.
Week 16.
Lecture 11: TI MSP430 Timers Compare Modes
Network and Systems Laboratory nslab.ee.ntu.edu.tw.
Automatic accident avoiding system PROJECT MEMBERS MUTHUKUMAR.K (05ME33) SAKTHIDHASAN.S (05ME39) SAKTHIVEL.N (05ME40) VINOTH.S (05ME56) PROJECT GUIDE:
8254 Timer.
Lab 3: ADC.
SGDRS Software System Design Justin A. King WWU EET Senior project 2013.
Seth Schwiethale James Crosetto James Ellison.  square pulse of ms, repeats every 20 ms  It is the same for both steering and acceleration 
Networked Embedded Systems Pengyu Zhang & Sachin Katti EE107 Spring 2016 Lecture 4 Timers and Interrupts.
HJD Institute of Technical Education & Research- Kera(Kutch) The 8051 Microcontroller architecture PREPARED BY: RAYMA SOHIL( )
ECE 382 Lesson 32 Lesson Outline Lab 6 Introduction Pulse Width Modulation Capture / Compare Example Lab 6 Tips Admin Lab#6 “prelab” due BOC lesson 33.
Recall the Container Thermometer
Why are Timer Functions Important?
Lecture 10: TI MSP430 Timers and Capture Modes
Application Case Study Security Camera Controller
Timers and Event Counters
ECE 3430 – Intro to Microcomputer Systems
Code review: GPIO, timer, and ISR
PWM and DC Motor Control
CS4101 Introduction to Embedded Systems Lab 6: Low-Power Optimization
Timer and Interrupts.
Chapter 6 General Purpose Input/Output
Prof. Chung-Ta King Department of Computer Science
ECE 3430 – Intro to Microcomputer Systems
AVR Addressing Modes Subject: Microcontoller & Interfacing
MSP432 ARM Timer Programming
ECE 3430 – Intro to Microcomputer Systems
ECE 3430 – Intro to Microcomputer Systems
CS4101 Introduction to Embedded Systems Lab 4: Interrupt
Introduction to Microprocessors and Microcontrollers
I/O PORTS : MSP430x5xx devices have up to 12 digital I/O ports :
ECE 3430 – Intro to Microcomputer Systems
Lecture 9: TI MSP430 Interrupts & Low Power Modes
ECE 3430 – Intro to Microcomputer Systems
CS4101 Introduction to Embedded Systems Lab 2: Basic IO and Timer
Prof. Chung-Ta King Department of Computer Science
MSP430 Clock System and Timer
ECE 3567 Microcontrollers Lab
Presentation transcript:

Network and Systems Laboratory nslab.ee.ntu.edu.tw

Network and Systems Laboratory nslab.ee.ntu.edu.tw When Setting Registers GPIO registers P1OUT = 0x80; P1IN, P1SEL …… What are these P1IN, P1OUT …… Register and bit definitions Registers are store here

Network and Systems Laboratory nslab.ee.ntu.edu.tw msp430x16x.h You see this #include Things that other done to make your life easier Most embedded systems programs include a header file which describes the target processor. Contains descriptions of interrupt vectors ROM and RAM sizes and locations register names and locations port names and locations register bit definitions macro definitions

Network and Systems Laboratory nslab.ee.ntu.edu.tw What’s Inside msp430x16x.h Define this name at this address DEFC –> 8-bit DEFW  16-bit This is why compiler understand P1IN, P1OUT, ……

Network and Systems Laboratory nslab.ee.ntu.edu.tw Interrupt Vectors This is why compiler understand PORT2_VECTOR

Network and Systems Laboratory nslab.ee.ntu.edu.tw What’s Inside msp430x16x.h You can do this Set bit 0 and bit 7 P1SEL |= BIT0 + BIT7; Clear bit 0 and bit 7 P1SEL &= ~(BIT0 + BIT7); There are many others You will meet them soon

Network and Systems Laboratory nslab.ee.ntu.edu.tw Things You Can Do The above are things that other done to make your life easier You can do something to make your life easier Hardware Abstraction Layer (HAL) Macros

Network and Systems Laboratory nslab.ee.ntu.edu.tw Hardware Abstraction Layer (HAL) An abstraction layer between software and hardware Implemented in software You can see it in Windows, Linux, embedded system, and etc. Provide application programming interfaces (APIs) Easily portable Intuitive name

Network and Systems Laboratory nslab.ee.ntu.edu.tw ; ; ; LEDs HAL You want to have a HAL for LEDs Example Filename: hal_LEDs.h Filename: hal_LEDs.c Macros Replace For short expression Functions Branch Need extra cycles

Network and Systems Laboratory nslab.ee.ntu.edu.tw MSP430 digitally controlled oscillator Low-frequency/high- frequency oscillator high-frequency oscillator (optional) MSP430 Clock System LFXT1CLK XT2CLK DCOCLK Clock Modules MCLK: Master Clock SMCLK: Sub-main clock ACLK: Auxiliary clock Clock Signals CPU Peripherals: Timer, UART, … KHz fixed rate

Network and Systems Laboratory nslab.ee.ntu.edu.tw Schematic Connected to a KHz watch crystal No second oscillator (XT2CLK)

Network and Systems Laboratory nslab.ee.ntu.edu.tw Adjusting DCO Frequency current injected into the DCO defines the fundamental frequency internal or external resistor controls the current three RSELx bits select one of eight nominal frequency ranges three DCOx bits divide the DCO range selected by the RSELx bits five MODx bits (modulation) further adjust the frequency

Network and Systems Laboratory nslab.ee.ntu.edu.tw Clock Module Registers

Network and Systems Laboratory nslab.ee.ntu.edu.tw BCSCTL1 ACLK Low Freq. (32.768K)?? High Freq. (450K ~ 8M)?? Divider = K8192

Network and Systems Laboratory nslab.ee.ntu.edu.tw BCSCTL2 No external resistor on Taroko

Network and Systems Laboratory nslab.ee.ntu.edu.tw Timer A counter that is incremented/decremented when the clock pulses Two timer on MSP430F1611 Timer A3 3 sets of configurable capture/compare registers Timer B7 7 sets of configurable capture/compare registers 16-bit timer at most count to /-1

Network and Systems Laboratory nslab.ee.ntu.edu.tw Timer Timer (counter) 0, 1, 2,…….,65534, ACLK SMCLK External signals eg. sensors, events Clock Signals Outputs Trigger External/internal event trigger an timer interrupt and record current counter value Timer Interval when counts to a certain value, generate an interrupt PWM output generate pulse width modulation (PWM)

Network and Systems Laboratory nslab.ee.ntu.edu.tw Its frequency changed by temperature and supply voltage Temperature drift = %/ o C Vcc Variation = 5 %/V (msp430f1611 datasheet) Clock Signals ACLK (Watch Crystal KHz) fixed rate Much accurate timing Slow startup (mS) SMCLK (DCO) Control its frequency in software less accurate Fast startup (< 6 μS) External signals Any devices that can generate 

Network and Systems Laboratory nslab.ee.ntu.edu.tw Counter 16-bit counter register TAR Increments/decrements with each rising edge of the clock signal 4 operating modes Stop Up – counts to TACCR0 Continuous – counts to 0xFFFF (65535) Up/down – counts to TACCR0 and back to zero

Network and Systems Laboratory nslab.ee.ntu.edu.tw Timer_A Control Register External clock sources If set, an interrupt is generated when timer resets to 0x0000 from any other value. (Overflow) There are many other interrupts that can be generate

Network and Systems Laboratory nslab.ee.ntu.edu.tw Capture/Compare Capture Catch an internal/external event Record the counter value to register (TACCRx) Generate an interrupt Compare Set a value in TACCRx When counter value (TAR) = TACCRx Generate an interrupt Set/reset/toggle an output signal Capture/compare register

Network and Systems Laboratory nslab.ee.ntu.edu.tw Usage of Capture Mode Record time event Speed computations Time measurements Example: Timer source = KHz; Continuous Mode TAR increment every 1/32768 second TAR (counter) Events TACCRx = 15000TACCRx = t1 = ( ) * (1/32768) seconds = second

Network and Systems Laboratory nslab.ee.ntu.edu.tw Usage of Compare Mode Usage Interrupts at specific time intervals. Generate PWM output signals Example: flash a LED every second Timer source = KHz; Up Mode Set TACCR0 to flash LED in the Timer_A0 ISR Interrupts

Network and Systems Laboratory nslab.ee.ntu.edu.tw Usage of Compare Mode Example: flash a LED every ½ second, flash another every 1.25 seconds Timer source = KHz; Continuous Mode Set TACCR1 = 16383; TACCR2 = TACCR 1 TACCR 2 In ISR TACCR1 += In ISR TACCR2 += Overflow TACCR2 += > TACCR2 = ; TACCR2 = 16383;

Network and Systems Laboratory nslab.ee.ntu.edu.tw Notes Continuous Mode Useful for generating multiple independent time intervals Time intervals can be produced with other modes TACCR0 is used as the period register Overflow handling is more complex

Network and Systems Laboratory nslab.ee.ntu.edu.tw Timer Output 7 output modes Control by TACCR0 and TACCRx (Action 1)/(Action 2) Counts to TACCRx, perform (Action 1)c Counts to TACCR0, perform (Action 1)c

Network and Systems Laboratory nslab.ee.ntu.edu.tw Where Are The Outputs Check device datasheet

Network and Systems Laboratory nslab.ee.ntu.edu.tw Timer Interrupts Interrupt sources Timer_A3 has 4 interrupt sources Timer_B7 has 8 interrupt sources Interrupt vectors There are two interrupt vectors for each timer (TA/TB)CCR0 interrupt vector for (TA/TB)CCR0 CCIFG TAIV interrupt vector for all other CCIFG flags and TAIFG Interrupt flags TACCR0 CCIFG flag is automatically reset when the TACCR0 interrupt request is serviced Any access, read or write, of the TAIV register automatically resets the highest pending interrupt flag

Network and Systems Laboratory nslab.ee.ntu.edu.tw Capture/Compare Control Register TACCTLx We use synchronous capture second capture was performed before the value from the first capture was read Where is the capture value?

Network and Systems Laboratory nslab.ee.ntu.edu.tw Robot Car Servo motors Robot Power (Vcc) Red Robot Ground (GND) Black Robot Signal White Battery Ground Black Battery Power Red

Network and Systems Laboratory nslab.ee.ntu.edu.tw Pulse Width Modulation Pulse Width Modulation (PWM) varying the pulse width Usage of PWM Control motor, telecommunication, voltage regulation, and etc. Pulse Pulse width Period

Network and Systems Laboratory nslab.ee.ntu.edu.tw Pulse Pulse width Period ≈ 20 ms Servo Motor A PWM input controls it angular position Pulse width = 1.5 ms; position = 90 o (neutral) Example pulse width = 1.25 ms; position = 0 o pulse width = 1.75 ms; position = 180 o Varies between brands and models The servo motor we used is Continuous Rotation model Other models will just move to the programmed position and stop

Network and Systems Laboratory nslab.ee.ntu.edu.tw Control Servo Motor The servo motors we used are 1.5 ms neutral If pulse width = 1.5 ms  stop If pulse width > 1.5 ms  rotate in one direction If pulse width < 1.5 ms  rotate in another direction Pulse Pulse width Period ≈ 20 ms

Network and Systems Laboratory nslab.ee.ntu.edu.tw Generate PWM Two ways Timer + GPIO Set/reset a GPIO pin inside timer ISR Controlled by software, need extra CPU cycles Timer output Use one of the timer output mode Totally controlled by hardware No interrupt required

Network and Systems Laboratory nslab.ee.ntu.edu.tw Timer + GPIO Use two timer interrupts to generate PWM Choose a GPIO pin to generate PWM control signal When TACCR0 generate interrupt, set this pin (period) When TACCRx generate interrupt, reset this pin (pulse width) Pulse Pulse width Period ≈ 20 ms

Network and Systems Laboratory nslab.ee.ntu.edu.tw Today’s Labs 1. MSP430 Clock system Use DCO as MCLK clock source Use Lab1_1 program file, changing DCO frequency Max frequency Approximate 1 MHz Observe the LED flash in different rate MCLK is used for CPU, When the speed of MCLK increase, this while loop will end faster

Network and Systems Laboratory nslab.ee.ntu.edu.tw Today’s Labs 2. Flash a LED every second (sample file on website) 1. You can use Timer_A3 or Timer_B7 2. Read user guide, find out related timer registers 3. Generate an interrupt every second, flash a LED in the ISR 4. For registers setting 1. Hexadecimal  0x Bit definitions  Check TI code examples to get some ideals TASSEL_0 TASSEL_1 TASSEL_2 TASSEL_3

Network and Systems Laboratory nslab.ee.ntu.edu.tw Today’s Labs 3. Generate multiple time interval 1. Flash a LED every second, flash another every 1.5 seconds 2. You need two interrupts 1. add another ISR by yourself 3. What mode should timer operate? Up mode? Continuous mode? 4. Control the servo motor on the robot car 1. Move forward, move backward