Presentation is loading. Please wait.

Presentation is loading. Please wait.

ECE 3567 Microcontroller Lab

Similar presentations


Presentation on theme: "ECE 3567 Microcontroller Lab"— Presentation transcript:

1 ECE 3567 Microcontroller Lab
Feedback Control Temperature and RC Voltage Dr. Gregg Chapman Spring 2019

2 ADC12 Review

3 The ADC12 Initialization Function
void Init_ADC12(void) { /************************************************************ Initialize Timer A1 as Sample Clock ******************************************************************************/ /*** TA1CTL ***/ TA1CTL = 0x0000; // Begin by clearing the register. TA1CTL |= 0x0100; // Select ACLK, and No Divide by /*** TA1CCTL1 ***/ TA1CCTL1 |= 0x00E0; // Select Compare Mode, Reset/Set Output Mode, and Interrupts DISABLED (rest are default) /*** TA1CCR0 ***/ TA1CCR0 = 0x2000; // Set Period to 2000 counts /*** TA1CCR1 ***/ TA1CCR1 = 0x1000; // Select 50% duty cycle (1000) /*** TA1CTL, Again ***/ TA1CTL |= 0x0010; // Set Timer to UP MODE /*************************************************************** Set-up Internal Voltage Reference ****************************************************************************/ REFCTL0 = 0x0001; /****************************************************** Configure P8.6 for ADC 5 (USED IN RC VOLTAGE FEEDBACK MODE) ***********************************************************/ P8DIR &=~0x40; // Bit 6 is INPUT P8SEL0 |= 0x40; // P8.6 is Primary Module function [01], ADC channel A5 P8SEL1 &=~0x40; /******************************************************************* Initialize the ADC12B Module *******************************************************************************/ ADC12CTL0 |= 0x8090; // Set Bit 15 and 11, Sample and Hold is 256 clock cycles for MEM0 - MEM31, ADCON ADC12CTL1 |= 0x322E; // Pre-divide = 4, ADC12SHS1 = 100 (4), Choose Sample Timer source(ADC12SHP), not inverted, Post-Divide = 2, ACLK, Repeat-Sequence-of-Channels, BIT 0 is read only // ADC12CTL2 is set-up for single ended channels and no differential pairs by default so it doesn't need configured /*** ADC12CTL3 ***/ ADC12CTL3 |=0x0080; // Set bit 7 ADC30 is internal Temperature Sensor for ADC Start Address /************** Set-up Memory Channels and sampling sequence **************/ ADC12MCTL0 |= 0x011E; //VREF and AVSS / Not end of Sequence / A30 / Sets 8, 4, 3, 2, and 1 ADC12MCTL1 |= 0x0085; // AVCC and AVSS / MEM1 is A5 and End of Sequence /******* NOTE THAT ADC12 Interrupt is from the buffer MEM1, NOT THE SAMPLE CLOCK *******/ /****************************************************************** START FREE RUNNING CONVERSIONS **********************************************************************************/ ADC12IFGR0 &= ~(BIT1); // Clear pending MEM1 interrupt flag ADC12IER0 |= BIT1; // Enable MEM1 Interrupt ADC12CTL0 |= 0x0003; // Start Converter in Repeat Sequence of Channels Mode }

4 Interrupt Service Routines
in main.c in unused_interrupts.c

5 (Pay particular attention to TS and RS formats)
Feedback Command Demo (Pay particular attention to TS and RS formats) NOTE: The temperature map was different when this was originally recorded.

6 Temperature Ranges A Handy Function (in RGB_LED.c) void update_RGB() {
if (T_Measure == TRUE) // Conditional on Temperature MODE if(degF <= 670) LED_Color = Purple; Flash = TRUE; // Below (or equal to) 67 degrees F, flashes Purple. Include both LED_Color and Flash } else if (degF <= 700) LED_Color = Purple; // Purple Flash = FALSE; else if (degF <= 730) LED_Color = Blue; // Blue else if (degF <= 760) LED_Color = Green; // Green else if (degF <= 790) LED_Color = Yellow; // Yellow else if (degF <= 820) LED_Color = Orange; // Orange else if (degF <= 850) LED_Color = Red; // Red else LED_Color = Red; // Above 85 degrees F, flashes RED Flash = TRUE; (in RGB_LED.c)

7 LED PWM Settings in RGB_LED.c

8 Timer_A0_ISR - Flash Function
Add code to the ISR to make the RGB LED Flash at 4 Hz whenever Flash = TRUE. Begin by testing whether or not the RGB LED is ENABLED Test whether or not Flash is TRUE Toggle the data directions to alternatively turn the LED off and on. IMPORTANT- What if the LED is “off” when Flash is set to FALSE? Add an else statement to address this problem

9 How to Implement the LED Flash in the Timer_A0
in main.c

10 Temperature Voltage Calculation and Display

11 Temperature Feedback Control

12 The Heater Circuit

13 Lab 5 Instructions and Checkpoints
Write a simple function called Temp_Feedback() in TempSensorMode.c file. Add the TS command shown in the video. Modify the TC and TF commands to re-calculate the temperature set point each time they are executed. Modify the main() while(1) loop to perform temperature feedback as shown in the video. Checkpoint 1: Demonstrate the temperature feedback mode using the TS command and 81 F. Change the display mode to TC. The MCU should regulate the temperature to 27 C. TF must work correctly when you change back from Celsius to Fahrenheit.

14 Temperature Feedback Control
in TempSensorMode.c

15 Pin Function Selection

16 Launch Pad Quick Start Guide

17 RC Voltage Control

18 The RC Circuit P2.1 PWM output RC charging circuit fcutoff = 6 Hz
ADC A5 P2.1 PWM output RC charging circuit A5 input on ADC12

19 Lab 5 Instructions and Checkpoints
Download the RCMode.c file from the ECE3567 website and add the .c file to your project Write Init_RC() to use P2.1 as a PWM output. Use TB0CCR5 for the RC duty cycle. ADD Init_RC() at the top of main().

20 RC Voltage Control in RC_Control.c
Add a PWM5 channel to Timer_B0 to control the RC Voltage on pin P2.1 The voltage is converted to digital on channel A5 (P8.6)

21 RC Voltage Control in RC_Control.c
Use PWM on CCR5 to keep the voltage within +/- 0.02V of the value set for RC_Data. If the voltage is in range, the LED should be Green. Otherwise, the LED should be Red. NOTE: You will need hysteresis on your control algorithm in order to make it work (Define a RANGE for both your control algorithm and the LED).

22 RC Voltage Control in main.c

23 RC Voltage Calculation and Display

24 Lab 5 Instructions and Checkpoints
Write code for RC_Feedback. Use a default set point of 3.30V. The selectable range is 0.05 to 3.30 V. (RS050 – RS330) If the voltage is more that 0.5V from the RS setpoint, use a step size of max_step_size (12) for the change in your PWM duty cycle. Once the voltage CROSSES the set point, reduce your step size to 1. DO NOT change the PWM if you are within +/ of the setpoint. Control the LED color accordingly.

25 RC Voltage Control Volts 3.30V max_step_size max_step_size RSxxx
Time

26 More on Commands

27 Lab 5 Instructions and Checkpoints
Add the RE, RD, and RS Commands. Configure P8.6 should have already been configured as the A5 in Init_ADC12();. Modify the main() while loop to perform RC Feedback. NOTE: call RC_Voltage() from main, NOT RC_Feedback. Checkpoint 2: Demonstrate the RC feedback mode using the RS command and 2.50V (RS250)and 0.75V (RS075). Demonstrate RE and RD. DD, DE, LD and LE should still function normally.

28 Command Length Modification
in parse_command() add You need the 3 data values to program set-points for both the temperature control and the RC voltage control Temperature data format places the least significant digit after the decimal point (e.g. 800 is 80.0 degrees) RC Voltage data format places two least significant digits after the decimal point (e.g. 250 is 2.50 volts)

29 Temperature Commands

30 LED Commands

31 (please change from CE and CD to this)
RC Voltage Commands LCD Display Commands (please change from CE and CD to this)

32 Lab 5 Checkpoints Checkpoint 1: Demonstrate the temperature feedback mode using the TS command and 81 F. Change the display mode to TC. The MCU should regulate the temperature to 27 C. TF must work correctly when you change back from Celsius to Fahrenheit. Checkpoint 2: Demonstrate the RC feedback mode using the RS command and 2.50V (RS250)and 0.75V (RS070). Demonstrate RE and RD. DD, DE, LD and LE should still function normally. Checkpoint 3: Demonstrate ALL of the Commands: LED Test Mode: LT, LH, LR, LO, LY, LG, LB, LP, LC, LD, LE Temperature Mode: TE, TD, TC, TF, TS, DD, DE, LD, LE RC Voltage Mode: RE, RD, RS, DD, DE, LD, LE


Download ppt "ECE 3567 Microcontroller Lab"

Similar presentations


Ads by Google