ece 3 3567 m microc ocon ontrol oller ers l lab
play

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


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

  2. ECE 3567 – Lab #3

  3. ECE 3567 – Lab #3

  4. ECE 3567 – Lab #3 normalized millicandelas wavelength (nm) wavelength (nm)

  5. ECE 3567 – Lab #2

  6. Quiz #2 Material

  7. I/O Ports Port Number and Bit Number TI Conventions From Lecture #2 This is the number of the BIT in the PORT This is the number of the PORT P3.6 - Bit 6 of Port3

  8. I/O Ports From Lecture #2

  9. I/O Ports From Lecture #2

  10. MSP430FR6989 HARDWARE Quick Start Guide From end of Lecture #2 This Document is Incorrect! 10

  11. MSP430FR6989 HARDWARE Quick Start Guide From end of Lecture #2 0 0 1 0 0 1 1 1 Default Secondary Primary Tertiary GPIO This Document is Incorrect! 11

  12. MSP430FR6989 HARDWARE Quick Start Guide FOR LAB #3 Secondary Secondary 12

  13. I/O Ports – Putting It All Together Example from end of Lecture #2 Secondary Function Suppose that you wanted to configure BIT 2 of PORT 2 as a Timer TB0.4 output for a PWM application Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 P2OUT X X X X X OUT X X P2DIR X X X X X 1 X X X X X X X 1 X X P2SEL1 X X X X X 0 X X P2SEL0 P2REN X X X X X X X X P2SEL0 |= BIT2; P2SEL1 &= ~BIT2; P2DIR |= BIT2;

  14. ECE 3567 – Lab #1 9. Based on the following schematic, configure the two GPIO pins as outputs using the registers and bitwise operators discussed in Lecture #2. 10. Turn ON the RED LED and turn OFF the GREEN LED. P1.0 P9.7 Jumpers are installed

  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.

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

  17. MSP430FR6989 HARDWARE FOR LAB #2 Tertiary 17

  18. MSP430FR6989 HARDWARE Quick Start Guide FOR LAB #3 Secondary Secondary 18

  19. MSP430FR6989 HARDWARE Quick Start Guide FOR LAB #3 Secondary Secondary

  20. Output Examples “Pulse Width Modulation”

  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.

  22. Laboratory #3

  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 4 th 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.

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

  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.

  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; }

  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 } } }

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

  29. ECE 3567 – Lab #3 Checkpoint #1: Demonstrate that your Lab #3 Project operates identically to Lab #2 AFTER making any changes to main.c, and UPDATING the 3567.h file.

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

  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; }

  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;

  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; }

  34. ECE 3567 – Lab #3 Checkpoint #2: Display your WHITE LED to the Lab Monitors

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

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend