908 Sim
-
Upload
muhammad-abid -
Category
Documents
-
view
71 -
download
5
Transcript of 908 Sim
© 2005 Microchip Technology Incorporated. All Rights Reserved. Slide 1
SIM 908
Using the MPLAB® Simulator and Stimulus
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 2
Class Objectives
When you walk out, you will know:
Different types of Stimulus and how to create/use them.
How to set up stimulus to test software.
Simulator debugging features and how to use them.
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 3
AgendaSimulators
UART1 IOReal-time Watch
Stimulus Asynchronous stimulus Demo/lab
Synchronous stimulus Demo/lab
Simulator debugging toolsExecution Trace
Logic Analyzer Demo/lab
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 4
Simulators
New Technology (speed x100)
UART1 output capability to a window (printf)
Message based stimulus for UART Rx
Logic Analyzer / Simple Trigger
Real Time Watch
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 5
Simulators
Stimulus Control Language (SCL) forStimulus
Execution Trace now has Filter in/outcapability
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 6
Why use a simulator...Combination of device simulation and stimulus
Develop before hardware is available
Repeatable testing of your Firmware
Load testing, multiple simultaneous IRQs
Free!!
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 7
UART1 IOOutput of the UART1 can be sent to a file or the output window (without stimulus)
Input from a file only
UART1 IO disables other stimulus Injection or Register Trace on RCREG only
Does not work for PIC17XXX family
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 8
UART1 IO with Printf
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 9
Configuring UART1 IOSelect Debugger>settings…Select Uart1 IOCheck EnableDetaches anystimulus filesconnected through SCL filesRewind data bufferFile Names orWindowed optionfor output
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 10
Real Time WatchUpdate File Register memory while running Debugger>SettingsRealtime Updates
Enable
Update timein 100msintervals
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 11
AgendaSimulators
UART1 IOReal-time Watch
Stimulus Asynchronous stimulus Demo/lab
Synchronous stimulus Demo/lab
Simulator debugging toolsExecution Trace
Logic Analyzer Demo/lab
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 12
Stimulus ??? What is it!
Stimulus is used to simulate target hardwareI/O to/from the PIC® microcontrollerIO can be:
Clock signals (Encoder)
Uart data (communications)
ADC data (Temperature Sensor)
Digital IO (switches)
and more
PIC microcontrollerdevice simulation
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 13
Types of Stimulus
Two basic types:Asynchronous and Synchronous
Asynchronous stimulus is predetermined data applied only when you click a button
Synchronous stimulus is predetermined data tied to an event such as reading/writing to an SFR, PC=value, Pin state change, Time ...
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 14
PROJECTPurpose: Provide stimulus to simulate
IO from the target hardware:
Objective: Learn how to use stimulus, stimulus workbook, generate SCL, attach SCL files, Logic analyzer and Trace
Uses: LAB_908.mcw workspaceADInputCh5.txtFiles: lab908.asmDevice: PIC16F917
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 15
PROJECT Heat unit controller
Monitor operations
Buttons adjust Temperature up/down
Both ButtonsFault State
Temperature
Heater
LED Temperature Display
FanLCD requested temperature
Read A/D
IRQIRQHandlerHandlerAdjust Adjust temps.temps.
&&Fault Fault
DetectDetect
Sleep
Test & adjustTest & adjustzone statezone state
StableStable
Update Temp.
PICPIC®® MCU firmwareMCU firmware
Port Bchange
ADCADC
UART1 Tx
Port D
Port D
Port C
Internal LCD controller
111
222
333
444
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 16
Temperature AdjustmentButtons adjust
Temperature up/down
Both ButtonsFault State
Read A/D
IRQIRQHandlerHandlerAdjust Adjust temps.temps.
&&Fault Fault
DetectDetect
Sleep
Test & adjustTest & adjustzone statezone state
StableStable
Update Temp.
PICPIC®® MCU firmwareMCU firmware
Port Bchange
111
Switches on Port B pins RB6 & RB7Will use Asynchronous stimulus to simulate
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 17
Asynchronous Stimulus
Getting started
Open a new scenario via theStimulus Controller
Debugger>Stimulus Controller>New Scenario
111
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 18
Asynchronous StimulusDefine Asynchronous Stimulus directly in the control window.
Fire button forevent
Save Scenario ofAsynchronousStimuli to restorelater
111
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 19
Applying the Switch Input
Open the existing workspace LAB_908.mcw
Apply a switch input to Port B<6> & Port B<7>
Pulse low for a period to activate
Open the Stimulus Controller from the debugger menu
Select the pin column and choose RB6Select the Action column and choose Pulse lowEnter a time in the width (15 cycles)
Do the same for RB7
111
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 20
Switch Inputs Complete
111
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 21
UART1 IORead A/D
IRQIRQHandlerHandlerAdjust Adjust temps.temps.
&&Fault Fault
DetectDetect
Sleep
Test & adjustTest & adjustzone statezone state
StableStable
Update Temp.
PICPIC®® MCU firmwareMCU firmware
222
Status messages on UART output
Will use UART1IO to monitor
Monitor operationsUART1 Tx
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 22
Apply UART1 IO
Enable the UART1 IO so a status message will be displayed when you press the buttons
Select Debugger\Settings
Select UART1 IO tab
Enable UART IO
Select output to window radio button
Press OK
222
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 23
UART1 IO Complete
Settings
Output
222
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 24
Test the CodeBuild reset and execute your program
Fire the Asynchronous stimulus
Status messages should appear on output window
Watch PORTB change in the watch window
Desired temperatures displayed within the EEPROM display view
TIP - Use Asynchronous Stimulus as a trigger or condition for Synchronous events
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 25
AgendaSimulators
UART1 IOReal-time Watch
Stimulus Asynchronous stimulus Demo/lab
Synchronous stimulus Demo/lab
Simulator debugging toolsExecution Trace
Logic Analyzer Demo/lab
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 26
Temperature SensorRead A/D
IRQIRQHandlerHandlerAdjust Adjust temps.temps.
&&Fault Fault
DetectDetect
Sleep
Test & adjustTest & adjustzone statezone state
StableStable
Update Temp.
PICPIC®® MCU firmwareMCU firmware
333
Temperature Sensor on A/D channel 5 PortE<0>
Will use Synchronous stimulus (specifically Register Injection) to simulate the sensor readings
TemperatureADCADC
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 27
Synchronous Stimulus
Predetermined data tied to an event.ALL synchronous stimuli are defined within a workbook.
The workbookgenerates Stimulus Control Language (SCL)code
333
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 28
Synchronous Stimulus
When attached the generated SCL code is loaded on a POR prior to execution
Hopper analogy
Event
Set RB2Clear RB3Assign ADRESL
Execute:- Set RB3 to 1
333
Event Execute:- Clear TMR1
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 29
Synchronous Stimulus
Getting started Need toGenerate theSCL code toperform all thestimulationrequired
CreateWorkbook
333
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 30
Synchronous Register Injection
Select SFR
Select Trigger
Select file, which mustexist
Select Formatof data
333
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 31
Temperature using Register Injection
Need to attach a data file to ADRESL (A/D result register) so the data can be injected into the ADC The data file exists and named ADInputCh5.txtOpen the SCL Generator from the debugger menu
Open workbook (NOT NEW) ... Lab908.sbsSelect the Register Injection tabSelect the ADRESL RegisterSelect Trigger to be DemandSelect the browse for file and select the file named above.Select Yes for rewindSelect Dec for the format
333
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 32
Temperature Injection Complete
333
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 33
Generating the SCLWork can be saved torestore later
To use thecreatedstimulus,you MUST generatethe SCL code
Stimuli onALL tabs are generated intoone SCL file
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 34
Using the SCL FileOpen or Select the Stimulus Controller windowPress Attachbutton to openbrowse window
Select SCL file
View Output toconfirm attach
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 35
Save and Use the Generated SCL
First select Save Workbook (give it a name)
Next press Generate SCL
Select (or Open) the Stimulus Controller
Attach the SCL file just created
Reset and Run the application
Press the buttons to adjust the temperature and
View output
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 36
Heater OutputRead A/D
IRQIRQHandlerHandlerAdjust Adjust temps.temps.
&&Fault Fault
DetectDetect
Sleep
Test & adjustTest & adjustzone statezone state
StableStable
Update Temp.
PICPIC®® MCU firmwareMCU firmware
444
The heater is turned on by the firmware setting PortC<5> highUse Synchronous stimulus (Register Trace) to monitor the PORTC readings
Port C Heater
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 37
Synchronous Register Trace
Select SFR
Select Trigger
Select file, or provide anew name
Select Formatof data
444
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 38
Monitor PORTC Heater Output
Need to attach a file to accept output from PORTC so the data can be written out anytime PORTC is updated Maximize or Open the SCL Generator workbook
Select the Register Trace tab
Select the PORTC Register
Select Trigger to be Demand
Select the browse for file and enter a file name
Select Raw for the format (ASCII)
444
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 39
Monitoring PORTC Complete
444
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 40
Save & Use the Updated SCL CodeSave Workbook
Generate SCL
Reset causes new SCL file to be re-loaded
Run the application
Press the buttons to adjust the temperature
Halt and detach the SCL file so PORTC_out.txt gets closed
View output file
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 41
Duration TestingSet the Asynchronous stimulus to occur Synchronously using large time units
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 42
Review
Asynchronous uses Controller - User initiated
Synchronous uses Workbook - Predefined
Use combinations of Synchronous stimuli to create more complex events
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 43
AgendaSimulators
UART1 IOReal-time Watch
Stimulus Asynchronous stimulus Demo/lab
Synchronous stimulus Demo/lab
Simulator debugging toolsExecution Trace
Logic Analyzer Demo/lab
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 44
Execution TraceSimulators contain an Execution TraceDisassembled opcodes with both Source and Destination Address and Data Tagged with execution cycleTrace has Filter capability (possible to set Filter IN/OUT from source file)To view the Trace select Menu item View > Simulator TraceTrace to Source correlation
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 45
Right mouse click in editor for context menu
Trace-INUse to tracespecificloops
Trace-OUTUse toeliminatewait loops
Filter Trace
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 46
Trace Buffer with Source View
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 47
Logic AnalyzerDisplays graphical I/O port data recorded in the Trace buffer. Trace MUST be enabledPort data is synchronized with the Trace dataSimple Triggers can be set to start or end data captureCursors for time measurementMaximum of 32 channelsPrintable displays
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 48
Logic Analyzer / Simple TriggerMenu item View>Simulator Logic AnalyzerSimpleTriggerdefinitions
Displaypropertybuttons
Zoom
Cursors
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 49
Logic Analyzer / Simple TriggerTo show signal data click Channels
Add theIO signalsyou wantto viewandpress OK
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 50
Logic Analyzer / Simple TriggerNo data lost whenswitchingchannels
Trigger setto PC
Time base
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 51
Use Logic AnalyzerReturn to project. Set a Breakpoint at the IRQ handler PORTBIRQ label, lab908.asmRight click at breakpoint and select Add Filter-In TraceLocate StartZone1 label. Highlight all of the subroutine, right click and Add Filter-In TraceOpen the Logic Analyzer. Select Channels and add RB6, RB7, RC5, RD2Reset and execute the program
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 52
Set Simple TriggerFire the Temperature Up or Down using Asynchronous stimulus pulse The program should stop on the first line of the PORTBIRQ handler Focus on the Logic AnalyzerPress Trigger now. Set Trigger position startRemove BreakpointReset, Execute, press temperature buttons to cycle the fan and heater. Then halt
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 53
Logic Analyzer / Simple TriggerFocus on Logic Analyzer
Select Cursors and measure cycles between
start of Fan and start of Heater
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 54
SIM 908 Simulator / Stimulus
Final Firmware Demo:
AH HA!!!!!
We have delivery of our hardware!!
We will run the same code used in the lab on real hardware
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 55
SUMMARY
Stimulus: Stimulus Control Language (SCL)
Register injection to unlimited number SFRs
Register injection on Demand, PC or Message
Port register injection
Register Trace
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 56
SUMMARY Stimulus
User defined pulse width on Asynchronous
Conditional start/stop on clock stimulus
Pin Stimulus on PC (using a condition)
Full or Partial SFR field assignments
UART1 IO
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 57
SUMMARY
Simulator:
Logic Analyzer
Real time watch variables
Trace In/Out or All
Simple Trigger using Logic Analyzer
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 58
AppendixSynchronous Stimulus Simple Pin/Register workbook tabSynchronous Stimulus Clock tabSynchronous Stimulus Advanced Pin/Register workbook tabAlternative way of duration testing using Advanced Pin/Register stimulusProject code featuresRegister Injection and Trace Formats
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 59
AppendixMessage based stimulus file format for RCREG SCL File formatSimulation of Grey Code encoderImporting old stimulus filesAlternative way of duration testing using simple stimulusLAB2 performing similar functions on a 16F688, with additional low power wake up and T1 gate functionality
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 60
Simple Pin/RegisterWorkbook currently openSimple Pin/SFRassignmentTime baseRadix for dataentry
Add or RemovePin/SFRs(signals)
Repeat list afterset time
Sample Workbook
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 61
Adding Removing SignalsAdd and RemovePin/SFRs
Select and Addor Removemultiple signals.
On OK. Columnsare aligned toorder of signals.
Sample Workbook
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 62
Time Base
Select Timebase for events.This is commonto all eventson this Tab.
Fields can be marked X or leftclear where nodata change isrequired.
Sample Workbook
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 63
Simple Pin / Register use
Asserting a bit field, pin or full SFR value at a specific time during the simulation.Repeat allows duration testingSetting two IRQ flags simultaneouslySpecific pulse length occurring at a specific time...
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 64
Clock Stimulus
Select Pinto applyclock to.
Conditionalstart or stopusing…- PC value- Absolutecycles
- Pin State
Sample Workbook
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 65
Clock Stimulus Use
Any type of clocking signals.TMR external clock signals.Grey code encoder input.I2C™ or SPI™ data clocking for setting IF flag....
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 66
Advanced Pin/Register
Assignments are based on a Conditionwhich can beANY.Set upconditionstatementsfirst.
Sample Workbook
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 67
Advanced Pin/Register
Defined conditions populate selection.
Conditions
Sample Workbook
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 68
Advanced Pin/Register
Select type of operation.
Continuousmode willallow a delayprior tore-testing thecondition.
Sample Workbook
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 69
Advanced Pin/RegisterSignal assignmenttakes placeonce conditionhas been met.A delay canbe placed onthe conditionprior to assignmentstaking place.
Sample Workbook
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 70
Advanced Pin/Register use
Complex assignments based on other signals.Provides more flexibility with gating and timingDuration testing, changing states.Setting IRQ flags, based on Clock stimulus.…
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 71
Duration Testing Example
Set Temperatures to change depending on the output of Heater/Fan pins.Use the Advanced Pin/Register stimulus, and set up RB7 to pulse high (Decrease temp) when RC5 goes high (heater) waiting 30 seconds before activation. Set RB6 to pulse high (Increase temp) when RD2 goes low (Fan) waiting 20 seconds before activation.
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 72
Duration Testing ExampleAdvanced Pin / Register
How can we make the pins pulse?
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 73
Duration Testing ExampleAdd 2 additional conditions, testing themselves.
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 74
Appendix Project code features
EEPROM for Temperature settingsRMS calculation for A/D readingsWDT Wake up enableKey press interruptUART for statusLookup tables for UART strings and RMS calculations
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 75
Appendix Register Injection and Trace FormatsHEX: White space delimited hex values 1FF AC 53 5FEDEC: White space delimited decimal values 128 75 145RAW: ASCII text This is an ASCII text string.PKT: Packet file for UART
//comments
wait 2 sec wait with valid time unit. hr, min, sec, ms, us, ns, ps
60 38 F2 HEX data
“This is text” ASCII text
SCL Format: B"01110000” binaryX”70” hex(base#value#Exponent) 2#1#E10 =16#4#E2 = 10#1024#E+00 = 1024
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 76
Appendix Message format
Message based file formatWait before startingHexadecimal values
Text Message
Wait betweenmessages
Random waitbetween 2 values
wait 0 sec61 62 63 20 6A 62 61wait 200 ms// the following is equivalent to "the quick brown fox""the quick brown ""fox"// CR-LF in a packetwait 20 sec65 66 67 68 13 1069 70// 9-bit value in a packetwait 20 sec165 166 167 168wait 30 ms// following is "012mix"32 33 34"mix"wait 100 ns// the following blank line is ignored
64 34 33 24 32 34 21rand 15 20 sec89 90 91 92 93 94rand 0 100 min11 22 33
CRLF
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 77
testbench for "dspic30f6014" is begin
process isbegin
report "SCL Loaded";wait;
end process;
IC2Stimulusrising:process is //RD0begin
report "IC2Stimulusrising 1stloop entry";loop
wait on OC1;exit when OC1!= '0';
end loop;report "IC2Stimulusrising 2ndloop entry";loop
IC2 <= '0'; wait for 1 ic;IC2 <= '1'; wait for 1 ic;exit when OC1 == '0';report "IC2Stimulusrising 2ndloop iteration";
end loop;report "IC2Stimulusrising 2ndloop exit";
end process IC2Stimulusrising;
end testbench;
Appendix SCL format
SCL based file formatDevice used
Processes
Begin/End blocks
Loops
Signal Assignments
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 78
Appendix Grey Code Encoder stimulus
Grey code encoder has 2 pulse trains, one out of phase with the other. When turning in one direction the phase A leads phase B. In the opposite direction phase B will lead phase A.
Encoder Phase A
Phase B
A goes high when B is low = ClockwiseA goes high when B is high = Anti-Clockwise
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 79
Appendix Grey Code Encoder stimulus
Encoder 64 counts/rev. At 300 RPM (5 RPS) we get 320 pulses per second. This is a 3125 us pulse so we will use 3us.At 20 MHZ we get0.2us InstructioncyclePulse width of6 cycles = 1.2usperiod for eachhalf of a fullwave. (2.4us pulse)
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 80
Appendix Old stimulus files
Import old files.You can import the old stimulus files usingthe Import/Merge button. This will also mergemultiple SCL files. NOTE: All mergingis appended to theend of the fileattached and modifiesthat file during amerge
Sample Scenario
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 81
Appendix LAB2
LAB2..
A similar project to the LAB_908 but on a PIC16F688 with Low power wake up pin, and T1 Gate functionality.
LAB2
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 82
Appendix Project 2
Project 2Purpose: Provide stimulus to simulate all
inputs and outputs normally comingfrom the target hardware:
Objective: Learn how to create a stimulus workbook, add stimulus, generate SCL, attach SCL files.Uses: Masters2_908.mcw workspace.
ADInputCh6Ch7.txtFiles: lab2908.asmDevice: 16F688
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 83
Appendix Project 2
Project 2 A/C unit controllerI/0 diagram
Project 2 A/C unit controllerI/0 diagram
RC0 Fan1 on/off
RC1 Compressor1 on/off
UART1 Tx
PIC16F688
KeyBoardTemperature
Zone1 up/down
RA1
RA2
WakeupLPWUE
RA0
Float Switchdrip pan level
RA3
TemperaturesZones 1 and 2
RC2 AN6
RC3 AN7
Zone 1Fan and Compressor
RC5 Compressor2 on/offZone 2
Compressor
PumpDrip pan pumpRA4
T1Gate
RC4
RC4 Fan2 on/off Zone 2Fan
Conditionally compiled
RA5 TMR1 CLKIPump Run
Time
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 84
Appendix Project 2Project A/C unit controller
Program flow
Project A/C unit controller
Program flowInitialize
Read A/DIRQIRQ
HandlerHandlerAdjust Adjust zone 1zone 1
requestedrequestedtemperaturetemperature
Turn onTurn onDrain panDrain pan
pumppump
Turn offTurn offpumppump
Sleep
Test & adjustTest & adjustzone statezone state
RA0 Wakeup
RC2 AN6
RC3 AN7
Set Zone stateRA1
RA2
Wakeup
RA3
Wakeup
StartingStarting
RunningRunning
StoppingStopping
RC0 Fan on
RC1 Comp off
RC0 Fan on
RC1 Comp off
RC0 Fan on
RC1 Comp on
StableStableNot
stable
TMR1 RA5
Wakeup
Zone 1Zone 1
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 85
Appendix project 2
Project demonstrates the following Features
EEPROM for Temperature settingsRMS calculation for A/D readings (not normal)External Timer 1 input using the Gate modeLow Power Wake up enableKey press interruptConditional compile to use UART for statusLookup tables for UART strings and RMS calculations
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 86
Appendix project 2
Open MPLAB® IDE. Select Masters2_908.mcw workspacefrom the LAB2_908 folder.Build project and run to ensure all is operational. Let’s Walk through the code.
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 87
Appendix Project 2
To initialize the low power wakeup pin we need to set this early to a high state.We will do thisby using simple Pin/Registerstimulus to setRA0 at 50 ic.
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 88
Appendix Project 2
Now to set the Low power wake up. We need to make RA0 go low as if the level to the pin dropped. Use Clock stimulus to set a clock on RA0. Begin at cycle = 100,000. Initial high, low for 2 and high for 9,999,998. End set at default Never. Under simulation this will wake the process about every 4 seconds.
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 89
Appendix Project 2
Stimulus dialog.
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 90
Appendix Project 2
Now set a clock of 1 cycle high 1 cycle low on TMR1CLKI pin RA5
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 91
Appendix Project 2
Now we need to connect a file to the A/D so we can simulate the temperature sensorsRegister Injection tab, select ADRESL and choose file ADInputCh6Ch7.txt as data inputSelect dec format as data is in decimalSelect rewind option so data buffer wraps around.
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 92
Appendix Project 2
Stimulus dialog.
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 93
Appendix Project 2
We would like to watch the UART1 output and see what the status is as we run the program.
Select Debugger\settingsClick on Uart1IO tab.Check the Enable Uart1 IO boxSelect the Radio button for window within the output area.OK. We have UART1 IO configured to go to the output window.
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 94
Appendix Project 2
Let’s reset and run the project again. Pay attention to the watch variables and see the ADRESL data values changing. Eventually the system will either stabilize in the Running or Stopped state.
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 95
Appendix Project 2
Stop the execution. Now set up some asynchronous stimuli.A pulse on RA1 to raise temperatureA pulse on RA2to lower temperatureA pulse on RA3for Float switch
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 96
Appendix Project 2
Re-run the program and use the Asynchronous stimuli to turn the system on or off and turn the pump on or off.