Presentation is loading. Please wait.

Presentation is loading. Please wait.

ECE 3567 Microcontrollers Syllabus – Autumn 2019

Similar presentations


Presentation on theme: "ECE 3567 Microcontrollers Syllabus – Autumn 2019"— Presentation transcript:

1

2 ECE 3567 Microcontrollers Syllabus – Autumn 2019

3 ECE 3567 Microcontrollers Syllabus – Autumn 2019

4 ECE 3567 Microcontrollers Syllabus – Autumn 2019

5 ECE 3567 Microcontrollers Syllabus – Autumn 2019

6 ECE 3567 Microcontrollers

7 ECE 3567 Microcontrollers

8 ECE 3567 Microcontrollers Lab Reports
Purpose – To verify that you have understood the lab Uses OSU standard format from Freshman Engineering There is a Template on the website. The grading rubric is published on the website.

9 ECE 3567 Microcontrollers Lab Reports - Rubric

10 The Laboratories

11 ECE 3567 Microcontrollers Labs
Lab 1 – Blinking LEDs Learn to create a project in Code Composer Studio (1 week) Get a project working Lab GPIO & Interrupts Learn to use Interrupt Service Routines and Timers (2 weeks) Control process timing Lab Pulse Width Modulation PWM, More Timers, Multicolored LED (2 weeks) Change the LED to any color Lab Analog to Digital Converter A-to-D Converter, Measure Voltage (2 weeks) Generate an analog DC voltage, then measure it digitally Lab 5 – Serial Communications UART, Command Structure (2 weeks) Set up a custom command structure over a serial port Lab 6 – Closed Loop Control Feedback Control, Control Voltage (2 weeks) Implement a closed loop controller for voltage setpoint. Indicate voltage range with LED color.

12 ECE 3567 Microcontrollers Embedded Hardware
Microprocessor (μP) Micro-Controller (MCU)

13 ECE 3567 Microcontrollers

14 ECE 3567 Microcontrollers

15 ECE 3567 Microcontrollers

16 ECE 3567 Microcontrollers

17 ECE 3567 Microcontrollers

18 The Development Platform

19 ECE 3567 Microcontrollers Code Composer Studio

20 ECE 3567 Microcontrollers Code Composer Studio

21 Embedded C Programming – Cross Compiler
Inputs: .c, .h Pre-processor output files Source files (MCU specific) Object files: .o, .obj Assembly: .asm, .a Executable: .hex, .bin Debugging, .lst is an ASM file

22 ECE 3567 Microcontrollers TI LaunchPad (MSP430FR6989)

23 ECE 3567 Microcontrollers Custom Designed BoosterPack
P2.1 RC PWM output RC charging circuit RGB PWMs to LED ADC – A5 fcutoff = 6 Hz A5 input on ADC12

24 The MSP430FR6989 Microcontroller Architecture
Timers: TA0 – ISR, Command, USCI_A0 TA1 – ADC12, USCI_A1 TB0 – PWMs

25 Why Should You Use Embedded C Programming

26 ECE 3567 Microcontrollers Embedded C Programming – C / Embedded C / ASM
C Programming Language Structure oriented Platform specific (processor) Compiler used to generate machine code Assumes FAST processor Generalized applications Requires an OS interface Embedded C Programming VERY different coding style Subset of C Can be faster and more efficient than “C” Hardware oriented Cross-compiler used to generate ASM, HEX, and Machine Code Microcontroller specific Smaller code size Speed limited by MCU Can be used to interface environment through sensors and actuators Lower cost than computer Lower power than computer More reliable that OS based systems Can provide better security Assembly Language Fastest Speed Smallest Code Size Too difficult for large scale projects

27 ECE 3567 Microcontrollers Embedded C Programming -Value
Programming Overall

28 ECE 3567 Microcontrollers Embedded C Programming -Value
Embedded Programming – 2010 to 2013

29 ECE 3567 Microcontrollers Embedded C Programming -Value
Embedded Programming – 2017

30 ECE 3567 Microcontrollers Embedded C Programming -Value
Embedded Programming – 2019, Overseas

31 Embedded C Programming

32 Embedded C Programming - Distinctives
Embedded C is a SUBSET of the C Programming Language Like assembly language, it is written to operate directly on HARDWARE ALL features of unique to C++ are nearly useless at the embedded level. High level software engineers NEARLY ALWAYS look down their nose at the embedded coding style. They consider it “sophomoric”, because it CANNOT take advantage of many aspects of high-level languages. (Don’t be one of those people. They only look foolish when the get to industry).

33 Embedded C Programming - Distinctives
Almost all embedded code is contained in HEADER files, both from the manufacturer and the person writing the code. Embedded code is MICROCONTROLLER SPECIFIC, and only portable to another application of the same MCU. Almost ALL embedded code has re-used files written for the same MCU Max Headroom

34 Embedded C Programming - Distinctives

35 Embedded C Programming - Distinctives
Trying to write embedded code without using the manufacturer’s header files is PURE INSANITY. Bela Lugosi

36 Take a 10 Minute Break

37 Documentation

38 ECE 3567 Microcontrollers Embedded C Programming – Documentation
1 – Create a documentation standard 2 – Use a consistent coding style 3 – Use a documentation template 4 – Use a file header 5 – Comment before coding 6 – Document as you go not afterwards 7 – Update comments when making coding changes 8 – Consistent use of commenting brackets and location 9 – Write non-obvious comments – Explain the why, NOT the how  10 – Provide example uses to increase clarity

39 ECE 3567 Microcontrollers Embedded C Programming – File headers (.c)

40 ECE 3567 Microcontrollers Embedded C Programming – Comments

41 Compiler directives and .h files

42 ECE 3567 Microcontrollers Embedded C Programming – Compiler Directives
#define – Declares a constant and may or may not give it a value. Can also be used to label a macro. #define RED 0x11 #include – A compiler directive that adds the contents of an external file to the current file definition. #include “stdio.h” // has to be between quotes or carrots <> #include “3567.h” Usage is reserved #pragma – Tells the compiler to include something once if it is included in multiple files. #ifdef – Conditional compilation based on a definition #endif #define __MSP430FR6989 #ifdef __MSP430FR6989__ #include <msp430fr6989.h> #else #include <msp430.h> #endif // __MSP430FR6989__

43 #typedef #typedef – Defines an alias name or a new type The typedefs for abbreviated variable types are defined in stdint.h typedef signed char int8_t; typedef unsigned char uint8_t; typedef int int16_t; typedef unsigned int uint16_t; typedef long int32_t; typedef unsigned long uint32_t; typedef long int64_t; typedef unsigned long uint64_t; const uint16_t BaseAddress; // Base Address of EUSCI_A port const uint8_t TxPort;// GPIO Port settings for TX pin

44 ECE 3567 Microcontrollers Embedded C Programming – TI header files (
ECE 3567 Microcontrollers Embedded C Programming – TI header files (.h) Structures #include "inc/hw_memmap.h" #include "adc12_b.h" #include "aes256.h" #include "comp_e.h" #include "crc.h" #include "crc32.h" #include "cs.h" #include "dma.h" #include "esi.h" #include "eusci_a_spi.h" #include "eusci_a_uart.h" #include "eusci_b_i2c.h" #include "eusci_b_spi.h" #include "framctl.h" #include "gpio.h" #include "lcd_c.h" #include "mpu.h" #include "mpy32.h" #include "pmm.h" #include "ram.h" #include "ref_a.h" #include "rtc_b.h" #include "rtc_c.h" #include "sfr.h" #include "sysctl.h" #include "timer_a.h" #include "timer_b.h" #include "tlv.h" #include "wdt_a.h" Compiler Directives typedef struct ADC12_B_initParam { //! Is the signal that will trigger a sample-and-hold for an input signal //! to be converted. uint16_t sampleHoldSignalSourceSelect; //! Selects the clock that will be used by the ADC12B core, and the uint8_t clockSourceSelect; //! Selects the amount that the clock will be divided. uint16_t clockSourceDivider; //! Selects the amount that the clock will be predivided. uint16_t clockSourcePredivider; //! Selects what internal channel to map for ADC input channels uint16_t internalChannelMap; } ADC12_B_initParam; #define ADC12_B_START_AT_ADC12MEM (ADC12CSTARTADD_0) #define ADC12_B_START_AT_ADC12MEM (ADC12CSTARTADD_1) #define ADC12_B_START_AT_ADC12MEM (ADC12CSTARTADD_2) #define ADC12_B_START_AT_ADC12MEM (ADC12CSTARTADD_3) #define ADC12_B_START_AT_ADC12MEM (ADC12CSTARTADD_4) #define ADC12_B_START_AT_ADC12MEM (ADC12CSTARTADD_5) #define ADC12_B_START_AT_ADC12MEM (ADC12CSTARTADD_6) #define ADC12_B_START_AT_ADC12MEM (ADC12CSTARTADD_7) #define ADC12_B_START_AT_ADC12MEM (ADC12CSTARTADD_8) #define ADC12_B_START_AT_ADC12MEM (ADC12CSTARTADD_9) #define ADC12_B_START_AT_ADC12MEM (ADC12CSTARTADD_10) #define ADC12_B_START_AT_ADC12MEM (ADC12CSTARTADD_11) #define ADC12_B_START_AT_ADC12MEM (ADC12CSTARTADD_12) #define ADC12_B_START_AT_ADC12MEM (ADC12CSTARTADD_13) #define ADC12_B_START_AT_ADC12MEM (ADC12CSTARTADD_14) #define ADC12_B_START_AT_ADC12MEM (ADC12CSTARTADD_15) #define ADC12_B_START_AT_ADC12MEM (ADC12CSTARTADD_16) TI “macro” functions or prototypes extern void ADC12_B_setAdcPowerMode(uint16_t baseAddress, uint8_t powerMode);

45 ECE 3567 Microcontrollers Embedded C Programming – Custom Header files (.h)

46 Embedded C Programming - Examples

47 ECE 3567 Microcontrollers Embedded C Programming – MicroChip (PICC)
/******************** Microchip Inc. PICC Process Code **************************/ #include <pic.h> #define XTAL_FREQ 4MHZ #include "delay.h" #include "delay.c" #define TIMEOUT //-- Minutes to timeout #define MAXTIME (TIMEOUT * 60 * )/ //-- us divided by 256 #define SECOND ( /256) //-- counts per second #define OFF //-- OFF State of output #define ON //-- ON State of output #define TIMEOUT_ON //-- ON State for Timeout LED #define TIMEOUT_OFF //-- OFF State for Timeout LED #define TRUE 1 #define FALSE 0 #define BITNUM(adr, bit) ((unsigned)(&adr)*8+(bit)) static bit DEAD @ BITNUM(GPIO, 0); //- Dangerously LOW static bit EMPTY @ BITNUM(GPIO, 1); //- Lower Limit static bit FULL @ BITNUM(GPIO, 2); //- Upper Limit static bit OUTPUT @ BITNUM(GPIO, 4); //- Output Control Pin static bit BITNUM(GPIO, 5); //- Timeout Indicator. unsigned long Counter; bit CountEnabled; bit Filling; bit TMRHIGH; //*************************************************************** //main void main (void) { char HourNotUp=0,Minute,Second; OPTION=0xD8; // Set up the option Register GPIO=0xFF; //-- All Outputs HIGH TIMEOUTPIN=TIMEOUT_OFF; //-- No Timeout yet so turn LED OFF OUTPUT=OFF; //-- Don't Fill so Output is OFF TRIS=0x0F; //-- Set Up 0 to 3 as input rest as output CountEnabled=0; Counter=0; Filling=0; TMRHIGH=0; while(1)

48 ECE 3567 Microcontrollers Embedded C Programming – Motorola
/******** ********* ********* ********* ********* ********* ********* *********/ void Tilt_ctl(void) { int i; unsigned int counter; TMSK1 &= 0xCF; /* disable timer 3, 4 interrupt */ counter = TCNT; /* get the current counter value */ TOC3 = counter ; /* set timer 3 to clock at +1ms */ TCTL1 = (TCTL1 & 0xCF) | 0x30; /* set timer 3 to go HIGH then */ TOC4 = counter ; /* set timer 4 to clock at +1ms */ TCTL1 = (TCTL1 & 0xF3) | 0x0C; /* set timer 4 to go HIGH then */ TFLG1 = 0x30; /* clear clocks on timers 3, 4 */ while ((TFLG1 & 0x20)==0){ i=i;} /* and wait until timers 3 fires */ TOC3 = counter ; /* set timer 3 to clock at +2ms */ TCTL1 = (TCTL1 & 0xCF) | 0x20; /* set timer 3 to go LOW then */ TOC4 = counter ; /* set timer 4 to clock at +7ms */ while ((TFLG1 & 0x10)==0){ i=i;} /* and wait until timers 4 fires */ adc_read(60,1); /* read the left TILT meter side */ adc_read(61,1); /* read the right TILT meter side */ TOC3 = counter ; /* set timer 3 to clock at +12ms */ TOC4 = counter ; /* set timer 4 to clock in +12ms */ TCTL1 = (TCTL1 & 0xF3) | 0x08; /* set timer 4 to go LOW then */ TOC4 = counter ; /* set timer 4 to clock in +22ms */ }

49 ECE 3567 Microcontrollers Embedded C Programming – Texas Instruments
/******** TI Code for MPS430 Power Management Module ********/ // pmm.c - Driver for the pmm Module. //******************************************************** //! \addtogroup pmm_api pmm #include "inc/hw_memmap.h" #ifdef __MSP430_HAS_PMM_FRAM__ #include "pmm.h" #include <assert.h> void PMM_enableSVSH (void) { HWREG8(PMM_BASE + OFS_PMMCTL0_H) = PMMPW_H; HWREG8(PMM_BASE + OFS_PMMCTL0_L) |= SVSHE; HWREG8(PMM_BASE + OFS_PMMCTL0_H) = 0x00; } void PMM_unlockLPM5 (void) { //Direct register access to avoid compiler warning - #10420-D //For FRAM devices, at start up, the GPO power-on default //high-impedance mode needs to be disabled to activate previously //configured port settings. This can be done by clearing the LOCKLPM5 //bit in PM5CTL0 register PM5CTL0 &= ~LOCKLPM5; }


Download ppt "ECE 3567 Microcontrollers Syllabus – Autumn 2019"

Similar presentations


Ads by Google