ECE 3 3567 M Microc ocon ontrol oller ers L Lab Laboratory #3 - - PowerPoint PPT Presentation

ece 3 3567 m microc ocon ontrol oller ers l lab
SMART_READER_LITE
LIVE PREVIEW

ECE 3 3567 M Microc ocon ontrol oller ers L Lab Laboratory #3 - - PowerPoint PPT Presentation

ECE 3 3567 M Microc ocon ontrol oller ers L Lab Laboratory #3 Pulse Width Modulation & RGB LED Autumn 2019 Dr. Gregg Chapman 1 ECE 3567 Lab #3 ECE 3567 Lab #3 ECE 3567 Lab #3 normalized millicandelas wavelength


slide-1
SLIDE 1

ECE 3 3567 M Microc

  • con
  • ntrol
  • ller

ers L Lab

Autumn 2019

  • Dr. Gregg Chapman

Laboratory #3 – Pulse Width Modulation & RGB LED

1

slide-2
SLIDE 2

ECE 3567 – Lab #3

slide-3
SLIDE 3

ECE 3567 – Lab #3

slide-4
SLIDE 4

ECE 3567 – Lab #3

wavelength (nm) wavelength (nm) millicandelas normalized

slide-5
SLIDE 5

ECE 3567 – Lab #2

slide-6
SLIDE 6

Quiz #2 Material

slide-7
SLIDE 7

I/O Ports Port Number and Bit Number TI Conventions P3.6 - Bit 6 of Port3

This is the number of the PORT This is the number of the BIT in the PORT

From Lecture #2

slide-8
SLIDE 8

I/O Ports

From Lecture #2

slide-9
SLIDE 9

I/O Ports

From Lecture #2

slide-10
SLIDE 10

MSP430FR6989 HARDWARE Quick Start Guide

10

From end of Lecture #2

This Document is Incorrect!

slide-11
SLIDE 11

MSP430FR6989 HARDWARE Quick Start Guide

11

From end of Lecture #2

This Document is Incorrect! 0 0 Default GPIO 1 0 Secondary 0 1 Primary 1 1 Tertiary

slide-12
SLIDE 12

MSP430FR6989 HARDWARE Quick Start Guide FOR LAB #3

12

Secondary Secondary

slide-13
SLIDE 13

I/O Ports – Putting It All Together

Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 X X X X X OUT X X X X X X X 1 X X X X X X X 1 X X X X X X X X X X X X X X X X X P2SEL0 P2SEL1 P2DIR P2OUT P2REN

Suppose that you wanted to configure BIT 2 of PORT 2 as a Timer TB0.4

  • utput for a PWM application

Example from end of Lecture #2

Secondary Function P2SEL0 |= BIT2; P2SEL1 &= ~BIT2; P2DIR |= BIT2;

slide-14
SLIDE 14

ECE 3567 – Lab #1

  • 9. Based on the following schematic, configure the two

GPIO pins as outputs using the registers and bitwise

  • perators discussed in Lecture #2.
  • 10. Turn ON the RED LED and turn OFF the GREEN LED.

P1.0 P9.7 Jumpers are installed

slide-15
SLIDE 15

ECE 3567 – Lab #2 Pulse Width Modulation

Add code to the Timer A0 Interrupt Service Routine to

  • 22. INCREMENT the Duty Cycle comparator (TA0CCR1) by 10 every

interrupt.

  • 23. If the Duty Cycle is >= 0x0CCD, reset it to 0x0010
  • 24. Configure P1.6 to output TA0.1

NOTE: You will need to change the pin function to TERTIARY, by programming bit 6 in both P1SEL0 and P1SEL1 to 1. Don’t forget to make P1.6 an OUTPUT.

  • 25. Connect CHANNEL 1 of the oscilloscope to P1.6 on the Launchpad

header and observe the Pulse Width Modulation. Save a few screen captures and explain what is happening in your Lab #2 report.

slide-16
SLIDE 16

MSP430FR6989 HARDWARE Quick Start Guide

16

0 0 Default GPIO 1 0 Secondary 0 1 Primary 1 1 Tertiary Output #, always the same as the duty cycle Comparator # Timer # P1SEL0 |= BIT6; P1SEL1 |= BIT6; P1DIR |= BIT6; This particular line is correct.

slide-17
SLIDE 17

MSP430FR6989 HARDWARE FOR LAB #2

17

Tertiary

slide-18
SLIDE 18

MSP430FR6989 HARDWARE Quick Start Guide FOR LAB #3

18

Secondary Secondary

slide-19
SLIDE 19

MSP430FR6989 HARDWARE Quick Start Guide FOR LAB #3

Secondary Secondary

slide-20
SLIDE 20

Output Examples

“Pulse Width Modulation”

slide-21
SLIDE 21

QUIZZES

  • Quizzes will be ONLINE in CARMEN for the rest of course.
  • You may take the quiz any time BEFORE or AFTER the Lab, up until MIDNIGHT on the final

day of each lab (second week).

  • 5 MULTIPLE CHOICE questions are chosen at random from 20 possible questions. Each

question is worth 1 point.

  • There is a 30-minute time limit for each attempt.
  • You may retake the quiz ONE TIME.
  • Grades are recorded automatically.
  • There is NO PARTIAL CREDIT.
slide-22
SLIDE 22

Laboratory #3

slide-23
SLIDE 23

Lab #3 - OVERVIEW

1) Download 3 files: Revised 3567.h, RGB_LED.c, and RC_Voltage.c and add them to your Lab 3 Project 2) Modify main.c to speed up ISR 3) In RGB_LED.c create an initialization function for 3 channels of Pulse Width Modulation, Init_PWM() 4) Configure the Init_PWM to set the duty cycles for fixed values that will make the RGB LED WHITE. 5) In RGB_LED.c create an update_RGB() function to increase the duty cycle on the RED PWM output channel. 6) Modify the main() function to ramp the duty cycle on the RED element of the RGB LED. 7) Modify update_RGB() to ramp the duty cycle on the GREEN element of the RGB LED. 8) Modify update_RGB() to ramp the duty cycle on the BLUE element of the RGB LED. 9) Modify the update_RGB() function to step through each color: WHITE, RED, ORANGE, YELLOW, GREEN, BLUE, and PURPLE. Call the function at the correct place in main() to update the LED color once every second. 10) In RC_Voltage.c create another initialization routine for a 4th channel of Pulse Width Modulation, Init_RC() 11) In RC_Voltage.c create a function called update_RC() that ramps the duty cycle on the correct PWM channel to change the RC FILTERED VOLTAGE from 0 to 3.29 Volts. Call this from main() to execute once a second. 12) In RC_Voltage.c, modify, update_RC() to change the color of the RGB LED every 0.55 Volts.

slide-24
SLIDE 24

ECE 3567 – Lab #3 Part 1 Clean-up main()

slide-25
SLIDE 25

ECE 3567 – Lab #3 Additional Files Needed

  • 1. Download the Lab3.zip under Lab 3 on the

ECE 3567 website and add the UPDATED ECE3567.h, RGB_LED.c, and RC_Voltage.c to your Lab 3 project.

slide-26
SLIDE 26

ECE 3567 – Lab #3 ISR Changes

  • 2. Change the Timer A0 ISR to:

#pragma vector=TIMER0_A0_VECTOR __interrupt void Timer_A(void) { NOTE 1: A function call here would execute how often?? ISR_Counter++; // Count ISRs if(ISR_Counter>=10) // 10 ISRs make 1 second { ISR_Flag = 1; // Flag to main() ISR_Counter=0; // Reset 1 Second counter } return; }

slide-27
SLIDE 27

ECE 3567 – Lab #3 main() Changes

  • 3. Change the main() function to:

void main (void) { //****** TI Macro used to stop the watchdog timer WDT_A_hold(__MSP430_BASEADDRESS_WDT_A__); //****** Disable the GPIO power-on default high-impedance mode PMM_unlockLPM5(); //*** Initializations *** Init_GPIO(); Init_Timer_A0(); //**************************** Enables all Configured Interrupts ***************** __enable_interrupt(); NOTE 2: A function call here would execute how often?? //******************* THE MAIN INFINITE LOOP **************************************** while(1) { NOTE 3: A function call here would execute how often?? if(ISR_Flag == 1) // Timer A0 has occurred. Used to count to 1 Second { NOTE 4: A function call here would execute how often?? // Alternates RED / GREEN) P1OUT ^= BIT0; // RED LED P9OUT ^= BIT7; // GREEN LED ISR_Flag = 0; // Clear Interrupt Service Flag } } }

slide-28
SLIDE 28
  • 4. The following Function prototypes have already been added to 3567.h:

void Init_GPIO(void); void Init_Timer_A0(void);

Copy the following functions after the ISR in main.c:

void Init_Timer_A0(void) { //*******Configure Timer A0 for a 10 Hz interrupt ****** TA0CCR0 = 0x0CCE; // for 10 Hz=100 ms and count is 3278 TA0CTL = 0x0110; // Set ACLK, UP MODE for Timer_0 TA0CCTL0 |= CCIE; // Enable interrupt for Timer_0 TA0CCTL1 = 0x04E0; // CCR1 reset/set TA0CCR1 = 0x0667; // CCR1 PWM at 50 % duty cycle, on TA0.1 P1DIR |= 0x40; P1SEL0 |=0x40; P1SEL1 |= 0x40; return; } void Init_GPIO(void) { //****** TI Macro Port Configurations for the RED and GREEN LEDs //****** Set pin P1.0 to output direction and turn LED off GPIO_setAsOutputPin( GPIO_PORT_P1, GPIO_PIN0 ); GPIO_setOutputHighOnPin( GPIO_PORT_P1, GPIO_PIN0 ); //****** Set pin P9.7 to output direction and turn LED off GPIO_setAsOutputPin( GPIO_PORT_P9, GPIO_PIN7 ); GPIO_setOutputLowOnPin( GPIO_PORT_P9, GPIO_PIN7 ); return; }

ECE 3567 – Lab #3 Add Functions

slide-29
SLIDE 29

ECE 3567 – Lab #3

Checkpoint #1: Demonstrate that your Lab #3 Project

  • perates identically to Lab #2 AFTER making any changes

to main.c, and UPDATING the 3567.h file.

slide-30
SLIDE 30

ECE 3567 – Lab #3 Part 2 Timer B0 Initialization, RGB LED PWM Initialization & the WHITE LED

slide-31
SLIDE 31

ECE 3567 – Lab #3 Part 2

void PWM_null() { duty_cycle_red = 0x000; duty_cycle_green = 0x000; duty_cycle_blue = 0x000; TB0CCR2 = 0000; TB0CCR3 = 0000; TB0CCR4 = 0000; return; }

slide-32
SLIDE 32

ECE 3567 – Lab #3 Part 2

/* RGB duty cycle variables */ volatile unsigned int duty_cycle_red; volatile unsigned int duty_cycle_green; volatile unsigned int duty_cycle_blue; volatile short LED_Color;

slide-33
SLIDE 33

ECE 3567 – Lab #3 Part 2

void Init_PWM(void){ unsigned int period = PERIOD; // Period is 0x0148 duty_cycle_red= 0x0100; // WHITE LED duty_cycle_green= 0x0120; duty_cycle_blue= 0x0120; LED_Color = White; // This variable is used to switch duty cycles in update_RGB // Set P2.2 to output // Set P2.2 to SECONDARY OUTPUT, TB0.4, (10) // Set P2.2 to SECONDARY OUTPUT, TB0.4, (10) // Set P3.6 and P3.7 to output // Set P3.6 and P3.7 to SECONDARY OUTPUT, TB0.2 and TB0.3, (10) // Set P3.6 and P3.7 to SECONDARY OUTPUT, TB0.2 and TB0.3, (10) TB0CTL = ; // ACLK, up mode TB0CCR0 = period; // PWM Period TB0CCTL2 = ; // CCR2 reset/set TB0CCR2 = duty_cycle_blue; // CCR2 PWM duty cycle, TB0.2 TB0CCTL3 = ; // CCR3 reset/set TB0CCR3 = duty_cycle_green; // CCR3 PWM duty cycle, TB0.3 TB0CCTL4 = ; // CCR4 reset/set TB0CCR4 = duty_cycle_red; // CCR4 PWM duty cycle, TB0.4 return; }

slide-34
SLIDE 34

ECE 3567 – Lab #3

Checkpoint #2: Display your WHITE LED to the Lab Monitors

slide-35
SLIDE 35

ECE 3567 – Lab #3 Part 3 Ramp Each Element of the RGB LED

slide-36
SLIDE 36

ECE 3567 – Lab #3 Part 3

void update_RGB() { /* Your Ramping CODE Goes Here. Edit and demonstrate the code for each of the 3 colors */ NOTE 1: Don’t allow the duty cycle to become larger than the period. NOTE 2: Where will you call this function so that the ramping is not too fast or too slow /* Always end by writing the duty_cycle_ variables the proper compare registers */ TB0CCR2 = duty_cycle_blue; // CCR2 PWM duty cycle is BLUE TB0CCR3 = duty_cycle_green; // CCR3 PWM duty cycle is GREEN TB0CCR4 = duty_cycle_red; // CCR4 PWM duty cycle is RED return; }

slide-37
SLIDE 37

ECE 3567 – Lab #3

Checkpoint #3: Display your RED GREEN and BLUE duty cycle ramping code to the Lab Monitors.

slide-38
SLIDE 38

ECE 3567 – Lab #3 Part 4 Change the RGB LED Color

slide-39
SLIDE 39

ECE 3567 – Lab #3 Part 4 - Change the RGB LED Color

Edit update_RGB() to change the color of the RGB LED once a second. Comment

  • ut the ramping code. Implement the following colors:

COLOR DUTY CYCLES RED GREEN BLUE RED 0x0070 0x0000 0x0000 ORANGE 0x00C4 0x0024 0x0000 YELLOW 0x00C4 0x00AB 0x0000 GREEN 0x0000 0x004A 0x0000 BLUE 0x0000 0x0000 0x007A PURPLE 0x0026 0x0000 0x007A WHITE 0x0100 0x0120 0x0120 Since the color #defines in 3567.h are sequential, you can increment LED_Color and loop back to RED after WHITE.

slide-40
SLIDE 40

ECE 3567 – Lab #3

Checkpoint #4: Display your update_RGB function to change colors every 1 second to the Lab Monitors

slide-41
SLIDE 41

ECE 3567 – Lab #3 Part 5 Initialize and Ramp the RC Voltage

slide-42
SLIDE 42

The RC Circuit

fcutoff = 6 Hz

ADC A5

A5 input on ADC12 RC charging circuit P2.1 PWM output

slide-43
SLIDE 43

ECE 3567 – Lab #3 Part 5 - Ramp the RC Voltage

Given that TB0.5 is the SECONDARY function on pin P2.1, write the code to initialize the PWM channel to the RC time constant. Call the function Init_RC() The function should be in the RC_Voltage.c file. NOTE: The xxxx.c files DO NOT require a #include to be compiled and linked in the project. Add the function call to the beginning of main().

slide-44
SLIDE 44

ECE 3567 – Lab #3 Part 5 - Ramp the RC Voltage

Write a function to increment the RC Voltage PWM and use it to ramp the RC Voltage from 0 to the value that sets the voltage to 3.29 V. Determine this value experimentally. Increment the duty cycle by a step size that results in a 10 millivolt change in the RC Voltage. Determine this value experimentally. Call the function update_RC() The function should be in the RC_Voltage.c file. Call the function in main() so that it executes once per second.

slide-45
SLIDE 45

ECE 3567 – Lab #3

Checkpoint #5: Display your update_RC() function to the Lab Monitors using a Digital Multi-meter to measure voltage.

slide-46
SLIDE 46

ECE 3567 – Lab #3 Part 6 Change the LED Color based

  • n RC Voltage Output
slide-47
SLIDE 47

ECE 3567 – Lab #3 Part 6

Write a function to increment the RC Voltage PWM and use it to ramp the RC Voltage from 0 to the value that sets the voltage to 3.29 V. Determine this value experimentally. Increment the duty cycle by a step size that results in a 10 millivolt change in the RC Voltage. Determine this value experimentally. Call the function update_RC() The function should be in the RC_Voltage.c file. Call the function in main() so that it executes once per second.

slide-48
SLIDE 48

ECE 3567 – Lab #3 Part 6 – Indicate the Voltage Range with the LED

Edit update_RGB() to change the color of the RGB LED to indicate which range the RC Voltage is in (see table). Comment out the previous code. COLOR Voltage Range Min Voltage (mV) Max Voltage (mV) RED 550 ORANGE 551 1100 YELLOW 1101 1650 GREEN 1651 2200 BLUE 2201 2750 PURPLE 2751 3290 WHITE * > 3290 NA Since the color #defines in 3567.h are sequential, you can increment LED_Color and loop back to RED after WHITE. * NOTE: Your code should NOT allow voltage this high. Include WHITE to indicate an OVERVOLTAGE.

slide-49
SLIDE 49

ECE 3567 – Lab #3 Part 6 – Indicate the Voltage Range with the LED

IN Lab #4 you will measure the RC Voltage using the Analog to Digital Converter. In Lab 3, you must base the LED color on the value that you are writing to the duty cycle register.

slide-50
SLIDE 50

ECE 3567 – Lab #3

Checkpoint #6: Demonstrate your MODIFIED update_RC() function that changes the LED color every 550 mV as the RC Voltage ramps up.

slide-51
SLIDE 51

ECE 3567 – Lab #3 End of Laboratory #3