Presentation is loading. Please wait.

Presentation is loading. Please wait.

Microcontroller Labs Lab 1 – The LED Test Mode Dr. Gregg Chapman

Similar presentations


Presentation on theme: "Microcontroller Labs Lab 1 – The LED Test Mode Dr. Gregg Chapman"— Presentation transcript:

1 Microcontroller Labs Lab 1 – The LED Test Mode Dr. Gregg Chapman
ECE 3567 Microcontroller Labs Lab 1 – The LED Test Mode Dr. Gregg Chapman

2 Lab 1 – LED Test Mode Goals
Set up Timer TB0 for Pulse Width Modulation on three outputs Make additions to the parse_Command( ) function to take action for all commands associated with the LED test Mode Modify the main.c loop to check for an active LED Test Mode Use the Timer 1 ISR routine to implement the “flashing” modes for the LH and LC commands.

3 Pulse Width Modulation Set-up
Write and initialization routine for Pulse Width Modulation, called Init_PWM() Configure three outputs: P3.6, P3.7, and P2.2 Set the Clock Period of the Timer for Pulse Width Modulation for TB0 Setup 3 Compare Registers to control the Duty Cycle of the Pulse Width Modulation Initialize the PWMs Add the Init_PWM() initialization Routine to main.c

4 Pulse Width Modulation Set-up

5 Pulse Width Modulation Set-up

6 Configure the Three Outputs
Set the data direction of the port pins using the PxDIR registers Select the Secondary Function for each of the outputs to be configuring the same bits in the PxSEL0 and PxSEL1 registers as you selected in the PxDIR register. Set the bits for PxSEL1 and clear the bits for PxSEL0

7 TB0 Timer In the Users Manual, read the section for Timer B (pp ), paying particular attention to the COMPARE MODE and OUTPUT MODE sections. TB0CTL is the Timer B Control Register TB0CCTLx are the Comparator Control Registers TB0R is the Timer B0 Count register TB0CCRn are the Compare Registers

8 TB0 Timer Registers Registers that you will need to program or initialize are indicated in RED.

9 TB0CTL page 678 of the Users Manual The register default is 0x0000
Verify 16 bit operation Select the ACLK as a timer source Place the timer in Up Mode

10 Compare Registers TB0CCR0 is the PERIOD count for the PWM repetition rate. The timer is set-up to run off of the ACLK = KHz The desired repetition rate for PWM is 10 milliSeconds (100Hz) Therefore value for this PERIOD is a count of 328, or 0x0148. This has been #defined for you as PERIOD. TB0.2 is connected to the P3.6 which is wired to the BLUE element in the RGB LED TB0CCR2 is written with values to change the DUTY CYCLE of the BLUE PWM TB0.3 is connected to the P3.7 which is wired to the GREEN element in the RGB LED TB0CCR3 is written with values to change the DUTY CYCLE of the GREEN PWM TB0.4 is connected to the P2.2 which is wired to the RED element in the RGB LED TB0CCR4 is written with values to change the DUTY CYCLE of the RED PWM Use the variables duty_cycle_blue, duty_cycle_green, and duty_cycle_red to update these 3 comparators Initialize the 3 pulse widths to 0x00FF NOTE: Never write values greater than the PERIOD (0x0148)

11 TB0CCTL2, TB0CCTL3 , TB0CCTL4 page 681 of the Users Manual
Using the Users Manual, figure out the CONTROL register values for each of the three duty cycle compares. All three are configured with the same value. The register default is 0x0000 Set the CLLD so that the TB0CLx (re)loads whenever the TBOR contains a count of 0. Select the OUTMOD so that the output is RESET when the timer counts to the TBxCLn value, and SET when the timer counts to the TBxCL0 value. CHECKPOINT 1: Show your Init_PWM() register values to a Lab Monitor to verify that they are correct before continuing.

12 Init_PWM() Should look similar to this:

13 Edit parse_Command () The function parse_Command() reads the two character command from the serial port and stores it in the volatile unsigned char Command. after the comet that says “Act on the Command”, add a switch (Command) statement that includes a case for every command. For the case: LT //LED Test Mode add the following code: LCD_Control = FALSE; // Boolean to turn off LCD LED_Control = TRUE; // Boolean to enable LED manual Control LED_Test = TRUE; // Boolean that LED Mode is enabled RC_Control = FALSE; // RC Voltage Mode is disabled T_Control = FALSE; // Temperature Control is disabled T_Measure = FALSE; // Temperature Mode is disabled clearLCD(); // Clear the LCD display toggle = 0; // Used for flashing the RGB LED Flash = FALSE; // Used for flashing the RGB LED LED_Color = No_Color; // Variable containing the current LED color break;

14 Edit parse_Command () For the cases: LT LH, LR, LO, LY, LG, LB, LP and LC Set LED_Color = (the name of the color as defined in 3567.h) Set Flash – Flash = FLASE; except for LH and LC. For those commands set Flash = TRUE;

15 Add update_RGB() to RGB.c
The function update_RGB() controls the PWM values to set the RGB LED to the appropriate color. Red - duty_cycle_red = 0x070; Blue - duty_cycle_red = 0x000; duty_cycle_green = 0x000; duty_cycle_green = 0x000; duty_cycle_blue = 0x000; duty_cycle_blue = 0x07A; Orange - duty_cycle_red = 0x0E4; Purple - duty_cycle_red = 0x00C; duty_cycle_green = 0x014; duty_cycle_green = 0x000; duty_cycle_blue = 0x000; duty_cycle_blue = 0x030; Yellow - duty_cycle_red = 0x0E4; duty_cycle_green = 0x08B; duty_cycle_blue = 0x000; Green - duty_cycle_red = 0x000; duty_cycle_green = 0x04A; duty_cycle_blue = 0x000

16 Add update_RGB() to RGB.c
Write nested IF-ELSE statements that tests LED_Color and sets the PWMs accordingly. The code should only execute if LED_Control is TRUE.

17 Add update_RGB() to RGB.c
At the end of update_RGB() write the duty_cycle values to the PWM comparators for each color. e.g. TB0CCR2 = duty_cycle_blue; // CCR2 PWM duty cycle etc. CHECKPOINT 2: Demonstrate the LT, LR, LO, LY,LG,LB, and LP commands to a Lab Monitor. Write a function called PWM_null() that sets all of the duty cycles and the three color comparator values to ZERO. Use this in combination with LED_Control to enable and disable the LED with the LE and LD commands respectively. CHECKPOINT 3: Demonstrate the LD and LE commands to a Lab Monitor

18 Changes to main.c Add (or uncomment) Init_PWM()
In the main loop, inside the (ISR_Flag == 1) if statement, add an if statement that runs update_RGB only if both LED_Test and LED_Control are both TRUE. Write code inside the Timer_A ISR makes the RGB LED Flash if LED_Control is TRUE and Flash is TRUE. You can use Toggle to track whether the LED is off or on. BIG HINT: The easiest way to turn each of the three RGB LED elements off and on is to set the PWM output pins to INPUTS and then back to OUTPUTS. This way, you don’t have to mess with the control registers or storing and restoring the PWM values. NOTE: The LED must Flash at EXACTLY 4 Hz to be given credit CHECKPOINT 4: Demonstrate the LC and LH commands to a Lab Monitor

19 Checkpoints for Today Show your Init_PWM() register values to a Lab Monitor to verify that they are correct before continuing. Demonstrate the LT, LR, LO, LY,LG,LB, and LP commands to a Lab Monitor. Demonstrate the LD and LE commands to a Lab Monitor Demonstrate the LC and LH commands to a Lab Monitor Replace all items in the bins or cabinet and clean off the Lab bench.


Download ppt "Microcontroller Labs Lab 1 – The LED Test Mode Dr. Gregg Chapman"

Similar presentations


Ads by Google