You are on page 1of 96

SIM 908

Using the MPLAB® Simulator and Stimulus

© 2005 Microchip Technology Incorporated. All Rights Reserved.

Slide

1

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

2

Agenda
Simulators
UART1 IO Real-time Watch

Stimulus
Asynchronous stimulus Demo/lab Synchronous stimulus Demo/lab

Simulator debugging tools
Execution Trace Logic Analyzer Demo/lab
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class

Slide

3

Class Slide 4 . All Rights Reserved.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.Simulators Stimulus Control Language (SCL) for Stimulus Execution Trace now has Filter in/out capability © 2005 Microchip Technology Incorporated. Class Slide 5 .

. All Rights Reserved. Class Slide 6 . Combination of device simulation and stimulus Develop before hardware is available Repeatable testing of your Firmware Load testing.Why use a simulator. multiple simultaneous IRQs Free!! © 2005 Microchip Technology Incorporated..

Class Slide 7 . All Rights Reserved.UART1 IO Output 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.

UART1 IO with Printf © 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 8 .

Class Slide 9 .Configuring UART1 IO Select Debugger>settings… Select Uart1 IO Check Enable Detaches any stimulus files connected through SCL files Rewind data buffer File Names or Windowed option for output © 2005 Microchip Technology Incorporated. All Rights Reserved.

All Rights Reserved. Class Slide 10 .Real Time Watch Update File Register memory while running Debugger> Settings Realtime Updates Enable Update time in 100ms intervals © 2005 Microchip Technology Incorporated.

Agenda Simulators UART1 IO Real-time Watch Stimulus Asynchronous stimulus Demo/lab Synchronous stimulus Demo/lab Simulator debugging tools Execution Trace Logic Analyzer Demo/lab © 2005 Microchip Technology Incorporated. Class Slide 11 . All Rights Reserved.

Stimulus ??? What is it! Stimulus is used to simulate target hardware I/O to/from the PIC® microcontroller IO can be: Clock signals (Encoder) Uart data (communications) ADC data (Temperature Sensor) Digital IO (switches) and more © 2005 Microchip Technology Incorporated. All Rights Reserved. Class PIC microcontroller device simulation Slide 12 .

All Rights Reserved. © 2005 Microchip Technology Incorporated. PC=value..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. Time . Pin state change. Class Slide 13 ..

mcw workspace ADInputCh5. All Rights Reserved.PROJECT Purpose: Provide stimulus to simulate IO from the target hardware: Objective: Learn how to use stimulus. attach SCL files. generate SCL.txt Files: lab908. Class Slide 14 .asm Device: PIC16F917 © 2005 Microchip Technology Incorporated. Logic analyzer and Trace Uses: LAB_908. stimulus workbook.

PROJECT Heat unit controller Buttons adjust Temperature up/down Port B change Both Buttons Fault State Monitor operations UART1 Tx LCD requested temperature Internal LCD controller Temperature Read A/D Update Temp. Class Slide 15 . & Fault Detect 3 2 Port C Heater 4 Stable Sleep Port D Fan PIC® MCU firmware © 2005 Microchip Technology Incorporated. ADC Port D LED Temperature Display Test & adjust zone state 1 IRQ Handler Adjust temps. All Rights Reserved.

& Fault Detect Test & adjust zone state Stable Sleep PIC® MCU firmware Slide 16 . 1 Both Buttons Fault State Switches on Port B pins RB6 & RB7 Will use Asynchronous stimulus to simulate © 2005 Microchip Technology Incorporated. Class IRQ Handler Adjust temps. All Rights Reserved.Temperature Adjustment Buttons adjust Temperature up/down Port B change Read A/D Update Temp.

Asynchronous Stimulus 1 Getting started Open a new scenario via the Stimulus Controller Debugger> Stimulus Controller >New Scenario © 2005 Microchip Technology Incorporated. Class Slide 17 . All Rights Reserved.

Asynchronous Stimulus 1 Define Asynchronous Stimulus directly in the control window. Class Slide 18 . Fire button for event Save Scenario of Asynchronous Stimuli to restore later © 2005 Microchip Technology Incorporated. All Rights Reserved.

Applying the Switch Input 1 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 RB6 Select the Action column and choose Pulse low Enter a time in the width (15 cycles) Do the same for RB7 © 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 19 .

Class Slide 20 . All Rights Reserved.Switch Inputs Complete 1 © 2005 Microchip Technology Incorporated.

UART1 IO 2 Read A/D Status messages on UART output Will use UART1IO to monitor Monitor operations UART1 Tx IRQ Handler Adjust temps. Test & adjust zone state Stable Sleep PIC® MCU firmware © 2005 Microchip Technology Incorporated. & Fault Detect Update Temp. Class Slide 21 . All Rights Reserved.

All Rights Reserved.Apply UART1 IO 2 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 © 2005 Microchip Technology Incorporated. Class Slide 22 .

UART1 IO Complete 2 Settings Output © 2005 Microchip Technology Incorporated. Class Slide 23 . All Rights Reserved.

Test the Code Build 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 . All Rights Reserved.Use Asynchronous Stimulus as a trigger or condition for Synchronous events © 2005 Microchip Technology Incorporated. Class Slide 24 .

Class Slide 25 . All Rights Reserved.Agenda Simulators UART1 IO Real-time Watch Stimulus Asynchronous stimulus Demo/lab Synchronous stimulus Demo/lab Simulator debugging tools Execution Trace Logic Analyzer Demo/lab © 2005 Microchip Technology Incorporated.

All Rights Reserved.Temperature Sensor Read A/D Update Temp. & Fault Detect Temperature Sensor on A/D channel 5 PortE<0> Will use Synchronous stimulus (specifically Register Injection) to simulate the sensor readings Class Test & adjust zone state Stable Sleep PIC® MCU firmware © 2005 Microchip Technology Incorporated. Temperature ADC 3 IRQ Handler Adjust temps. Slide 26 .

ALL synchronous stimuli are defined within a workbook. The workbook generates Stimulus Control Language (SCL) code © 2005 Microchip Technology Incorporated. Class Slide 27 .Synchronous Stimulus 3 Predetermined data tied to an event. All Rights Reserved.

Slide 28 . All Rights Reserved.Set RB3 to 1 Execute:.Clear TMR1 Class © 2005 Microchip Technology Incorporated.Synchronous Stimulus 3 When attached the generated SCL code is loaded on a POR prior to execution Hopper analogy Set RB2 Clear RB3 Assign ADRESL Event Event Execute:.

Synchronous Stimulus 3 Getting started Need to Generate the SCL code to perform all the stimulation required Create Workbook © 2005 Microchip Technology Incorporated. Class Slide 29 . All Rights Reserved.

Class Slide 30 .Synchronous Register Injection 3 Select SFR Select Trigger Select file. which must exist Select Format of data © 2005 Microchip Technology Incorporated. All Rights Reserved.

txt Open the SCL Generator from the debugger menu Open workbook (NOT NEW) . All Rights Reserved..sbs Select the Register Injection tab Select the ADRESL Register Select Trigger to be Demand Select the browse for file and select the file named above. Select Yes for rewind Select Dec for the format © 2005 Microchip Technology Incorporated..Temperature using Register Injection 3 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. Class Slide 31 . Lab908.

All Rights Reserved.Temperature Injection Complete 3 © 2005 Microchip Technology Incorporated. Class Slide 32 .

Class Slide 33 .Generating the SCL Work can be saved to restore later To use the created stimulus. All Rights Reserved. you MUST generate the SCL code Stimuli on ALL tabs are generated into one SCL file © 2005 Microchip Technology Incorporated.

Class Slide 34 . All Rights Reserved.Using the SCL File Open or Select the Stimulus Controller window Press Attach button to open browse window Select SCL file View Output to confirm attach © 2005 Microchip Technology Incorporated.

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. Class Slide 35 . All Rights Reserved.

All Rights Reserved. Class Slide 36 . 4 IRQ Handler Adjust temps.Heater Output Read A/D Update Temp. & Fault Detect Test & adjust zone state The heater is turned on by the firmware setting PortC<5> high Use Synchronous stimulus (Register Trace) to monitor the PORTC readings Port C Heater Stable Sleep PIC® MCU firmware © 2005 Microchip Technology Incorporated.

All Rights Reserved. Class Slide 37 . or provide a new name Select Format of data © 2005 Microchip Technology Incorporated.Synchronous Register Trace 4 Select SFR Select Trigger Select file.

Class Slide 38 . All Rights Reserved.Monitor PORTC Heater Output 4 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) © 2005 Microchip Technology Incorporated.

Monitoring PORTC Complete 4 © 2005 Microchip Technology Incorporated. Class Slide 39 . All Rights Reserved.

Save & Use the Updated SCL Code Save 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. All Rights Reserved. Class Slide 40 .txt gets closed View output file © 2005 Microchip Technology Incorporated.

Duration Testing Set the Asynchronous stimulus to occur Synchronously using large time units © 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 41 .

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

42

Agenda
Simulators
UART1 IO Real-time Watch

Stimulus
Asynchronous stimulus Demo/lab Synchronous stimulus Demo/lab

Simulator debugging tools
Execution Trace Logic Analyzer Demo/lab
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class

Slide

43

Execution Trace
Simulators contain an Execution Trace Disassembled opcodes with both Source and Destination Address and Data Tagged with execution cycle Trace has Filter capability (possible to set Filter IN/OUT from source file) To view the Trace select Menu item View > Simulator Trace Trace to Source correlation
© 2005 Microchip Technology Incorporated. All Rights Reserved. Class

Slide

44

Filter Trace Right mouse click in editor for context menu Trace-IN Use to trace specific loops Trace-OUT Use to eliminate wait loops © 2005 Microchip Technology Incorporated. Class Slide 45 . All Rights Reserved.

All Rights Reserved.Trace Buffer with Source View © 2005 Microchip Technology Incorporated. Class Slide 46 .

All Rights Reserved. Trace MUST be enabled Port data is synchronized with the Trace data Simple Triggers can be set to start or end data capture Cursors for time measurement Maximum of 32 channels Printable displays © 2005 Microchip Technology Incorporated. Class Slide 47 .Logic Analyzer Displays graphical I/O port data recorded in the Trace buffer.

Class Slide 48 . All Rights Reserved.Logic Analyzer / Simple Trigger Menu item View>Simulator Logic Analyzer Simple Trigger definitions Display property buttons Zoom Cursors © 2005 Microchip Technology Incorporated.

All Rights Reserved.Logic Analyzer / Simple Trigger To show signal data click Channels Add the IO signals you want to view and press OK © 2005 Microchip Technology Incorporated. Class Slide 49 .

Logic Analyzer / Simple Trigger No data lost when switching channels Trigger set to PC Time base © 2005 Microchip Technology Incorporated. Class Slide 50 . All Rights Reserved.

lab908. RD2 Reset and execute the program © 2005 Microchip Technology Incorporated. RC5. All Rights Reserved. Class Slide 51 .Use Logic Analyzer Return to project. Highlight all of the subroutine.asm Right click at breakpoint and select Add Filter-In Trace Locate StartZone1 label. Set a Breakpoint at the IRQ handler PORTBIRQ label. Select Channels and add RB6. RB7. right click and Add Filter-In Trace Open the Logic Analyzer.

Then halt © 2005 Microchip Technology Incorporated. Execute.Set Simple Trigger Fire 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 Analyzer Press Trigger now. press temperature buttons to cycle the fan and heater. Class Slide 52 . All Rights Reserved. Set Trigger position start Remove Breakpoint Reset.

All Rights Reserved.Logic Analyzer / Simple Trigger Focus on Logic Analyzer Select Cursors and measure cycles between start of Fan and start of Heater © 2005 Microchip Technology Incorporated. Class Slide 53 .

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 54 .

SUMMARY Stimulus: Stimulus Control Language (SCL) Register injection to unlimited number SFRs Register injection on Demand. All Rights Reserved. PC or Message Port register injection Register Trace © 2005 Microchip Technology Incorporated. Class Slide 55 .

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. Class Slide 56 . All Rights Reserved.

Class Slide 57 . All Rights Reserved.SUMMARY Simulator: Logic Analyzer Real time watch variables Trace In/Out or All Simple Trigger using Logic Analyzer © 2005 Microchip Technology Incorporated.

Class Slide 58 . All Rights Reserved.Appendix Synchronous Stimulus Simple Pin/Register workbook tab Synchronous Stimulus Clock tab Synchronous Stimulus Advanced Pin/Register workbook tab Alternative way of duration testing using Advanced Pin/Register stimulus Project code features Register Injection and Trace Formats © 2005 Microchip Technology Incorporated.

Class Slide 59 . with additional low power wake up and T1 gate functionality © 2005 Microchip Technology Incorporated.Appendix Message based stimulus file format for RCREG SCL File format Simulation of Grey Code encoder Importing old stimulus files Alternative way of duration testing using simple stimulus LAB2 performing similar functions on a 16F688. All Rights Reserved.

All Rights Reserved. Class Sample Workbook Slide 60 .Simple Pin/Register Workbook currently open Simple Pin/SFR assignment Time base Radix for data entry Add or Remove Pin/SFRs (signals) Repeat list after set time © 2005 Microchip Technology Incorporated.

All Rights Reserved. Sample Workbook © 2005 Microchip Technology Incorporated. Columns are aligned to order of signals. Class Slide 61 .Adding Removing Signals Add and Remove Pin/SFRs Select and Add or Remove multiple signals. On OK.

Class Slide 62 . All Rights Reserved. Fields can be marked X or left clear where no data change is required.Time Base Sample Workbook Select Time base for events. This is common to all events on this Tab. © 2005 Microchip Technology Incorporated.

pin or full SFR value at a specific time during the simulation..Simple Pin / Register use Asserting a bit field. © 2005 Microchip Technology Incorporated. Class Slide 63 . Repeat allows duration testing Setting two IRQ flags simultaneously Specific pulse length occurring at a specific time .. All Rights Reserved.

Pin State Sample Workbook © 2005 Microchip Technology Incorporated. Conditional start or stop using… .Absolute cycles . Class Slide 64 .Clock Stimulus Select Pin to apply clock to.PC value . All Rights Reserved.

All Rights Reserved. Grey code encoder input..Clock Stimulus Use Any type of clocking signals. Class Slide 65 . © 2005 Microchip Technology Incorporated. I2C™ or SPI™ data clocking for setting IF flag. . TMR external clock signals..

Advanced Pin/Register Sample Workbook Assignments are based on a Condition which can be ANY. Class Slide 66 . Set up condition statements first. © 2005 Microchip Technology Incorporated. All Rights Reserved.

Advanced Pin/Register Sample Workbook Defined conditions populate selection. Class Slide 67 . All Rights Reserved. Conditions © 2005 Microchip Technology Incorporated.

All Rights Reserved. Class Slide 68 . © 2005 Microchip Technology Incorporated.Advanced Pin/Register Sample Workbook Select type of operation. Continuous mode will allow a delay prior to re-testing the condition.

A delay can be placed on the condition prior to assignments taking place. Sample Workbook © 2005 Microchip Technology Incorporated. Class Slide 69 . All Rights Reserved.Advanced Pin/Register Signal assignment takes place once condition has been met.

Class Slide 70 . All Rights Reserved. based on Clock stimulus. changing states.Advanced Pin/Register use Complex assignments based on other signals. Provides more flexibility with gating and timing Duration testing. Setting IRQ flags. … © 2005 Microchip Technology Incorporated.

All Rights Reserved. and set up RB7 to pulse high (Decrease temp) when RC5 goes high (heater) waiting 30 seconds before activation. Use the Advanced Pin/Register stimulus. Class Slide 71 . © 2005 Microchip Technology Incorporated. Set RB6 to pulse high (Increase temp) when RD2 goes low (Fan) waiting 20 seconds before activation.Duration Testing Example Set Temperatures to change depending on the output of Heater/Fan pins.

Duration Testing Example Advanced Pin / Register How can we make the pins pulse? © 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 72 .

© 2005 Microchip Technology Incorporated. Class Slide 73 . All Rights Reserved. testing themselves.Duration Testing Example Add 2 additional conditions.

All Rights Reserved. Class Slide 74 .Appendix Project code features EEPROM for Temperature settings RMS calculation for A/D readings WDT Wake up enable Key press interrupt UART for status Lookup tables for UART strings and RMS calculations © 2005 Microchip Technology Incorporated.

us. hr. PKT: Packet file for UART //comments wait 2 sec wait with valid time unit. All Rights Reserved. sec. ms. Class Slide 75 . ns.Appendix Register Injection and Trace Formats HEX: White space delimited hex values 1FF AC 53 5FE DEC: White space delimited decimal values 128 75 145 RAW: ASCII text This is an ASCII text string. min. ps 60 38 F2 HEX data ASCII text “This is text” SCL Format: B"01110000” binary X”70” hex (base#value#Exponent) 2#1#E10 =16#4#E2 = 10#1024#E+00 = 1024 © 2005 Microchip Technology Incorporated.

Class Slide 76 .Appendix Message format Message based file format Wait before starting Hexadecimal values Text Message Wait between messages Random wait between 2 values wait 0 sec 61 62 63 20 6A 62 61 wait 200 ms // the following is equivalent to "the quick brown fox" "the quick brown " "fox" // CR-LF in a packet CR wait 20 sec LF 65 66 67 68 13 10 69 70 // 9-bit value in a packet wait 20 sec 165 166 167 168 wait 30 ms // following is "012mix" 32 33 34 "mix" wait 100 ns // the following blank line is ignored 64 34 33 24 32 34 21 rand 15 20 sec 89 90 91 92 93 94 rand 0 100 min 11 22 33 © 2005 Microchip Technology Incorporated. All Rights Reserved.

IC2Stimulusrising:process is //RD0 begin report "IC2Stimulusrising 1stloop entry". wait. end process. wait for 1 ic. end loop. end loop. IC2 <= '1'. end testbench. loop IC2 <= '0'.Appendix Device used Processes SCL format SCL based file format testbench for "dspic30f6014" is begin process is begin report "SCL Loaded". exit when OC1!= '0'. end process IC2Stimulusrising. loop wait on OC1. Begin/End blocks Loops Signal Assignments © 2005 Microchip Technology Incorporated. report "IC2Stimulusrising 2ndloop iteration". wait for 1 ic. exit when OC1 == '0'. report "IC2Stimulusrising 2ndloop exit". report "IC2Stimulusrising 2ndloop entry". Class Slide 77 . All Rights Reserved.

Class Slide 78 .Appendix Grey Code Encoder stimulus Grey code encoder has 2 pulse trains. When turning in one direction the phase A leads phase B. All Rights Reserved. Encoder Phase A Phase B A goes high when B is low = Clockwise A goes high when B is high = Anti-Clockwise © 2005 Microchip Technology Incorporated. In the opposite direction phase B will lead phase A. one out of phase with the other.

Appendix Grey Code Encoder stimulus Encoder 64 counts/rev. At 20 MHZ we get 0. (2. All Rights Reserved.2us period for each half of a full wave.4us pulse) © 2005 Microchip Technology Incorporated. Class Slide 79 . This is a 3125 us pulse so we will use 3us. At 300 RPM (5 RPS) we get 320 pulses per second.2us Instruction cycle Pulse width of 6 cycles = 1.

Sample Scenario You can import the old stimulus files using the Import/Merge button.Appendix Old stimulus files Import old files. Class Slide 80 . NOTE: All merging is appended to the end of the file attached and modifies that file during a merge © 2005 Microchip Technology Incorporated. This will also merge multiple SCL files. All Rights Reserved.

Appendix LAB2 LAB2 LAB2. All Rights Reserved. A similar project to the LAB_908 but on a PIC16F688 with Low power wake up pin. Class Slide 81 . © 2005 Microchip Technology Incorporated.. and T1 Gate functionality.

Appendix Project 2 Project 2 Purpose: Provide stimulus to simulate all inputs and outputs normally coming from the target hardware: Objective: Learn how to create a stimulus workbook. Class Slide 82 . attach SCL files.mcw workspace. All Rights Reserved. Uses: Masters2_908.txt Files: lab2908. ADInputCh6Ch7. add stimulus. generate SCL.asm Device: 16F688 © 2005 Microchip Technology Incorporated.

All Rights Reserved.Appendix Project 2 Project 2 A/C unit controller KeyBoard Temperature Zone1 up/down Conditionally compiled RC4 Fan2 on/off Zone 2 Fan I/0 diagram RA1 RA2 RC4 UART1 Tx Pump Wakeup LPWUE RA0 PIC16F688 RC0 Fan1 on/off RA4 T1Gate Drip pan pump Float Switch drip pan level RA3 Zone 1 Fan and Compressor RC1 Compressor1 on/off Temperatures Zones 1 and 2 RC2 AN6 RC3 AN7 RC5 Compressor2 on/off Zone 2 Compressor Pump Run Time RA5 TMR1 CLKI © 2005 Microchip Technology Incorporated. Class Slide 83 .

Class Slide 84 .Appendix Project 2 RC2 AN6 RC3 AN7 Project A/C unit controller Program flow RC0 Fan on RC1 Comp off Initialize Read A/D IRQ Handler RA1 RA2 Wakeup Set Zone state Starting Test & adjust zone state Not stable Zone 1 RC0 Fan on RC1 Comp on Adjust zone 1 requested temperature Running Stopping Wakeup RA3 Turn on Drain pan pump Turn off pump Stable Sleep RC0 Fan on RC1 Comp off RA0 Wakeup Wakeup TMR1 RA5 © 2005 Microchip Technology Incorporated. All Rights Reserved.

All Rights Reserved.Appendix project 2 Project demonstrates the following Features EEPROM for Temperature settings RMS calculation for A/D readings (not normal) External Timer 1 input using the Gate mode Low Power Wake up enable Key press interrupt Conditional compile to use UART for status Lookup tables for UART strings and RMS calculations © 2005 Microchip Technology Incorporated. Class Slide 85 .

mcw workspace from the LAB2_908 folder. All Rights Reserved. Let’s Walk through the code.Appendix project 2 Open MPLAB® IDE. Select Masters2_908. Class Slide 86 . © 2005 Microchip Technology Incorporated. Build project and run to ensure all is operational.

We will do this by using simple Pin/Register stimulus to set RA0 at 50 ic. All Rights Reserved. Class Slide 87 . © 2005 Microchip Technology Incorporated.Appendix Project 2 To initialize the low power wakeup pin we need to set this early to a high state.

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

88

Appendix Project 2
Stimulus dialog.

© 2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

89

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

90

Appendix Project 2 Now we need to connect a file to the A/D so we can simulate the temperature sensors Register Injection tab. © 2005 Microchip Technology Incorporated. Class Slide 91 . All Rights Reserved. select ADRESL and choose file ADInputCh6Ch7.txt as data input Select dec format as data is in decimal Select rewind option so data buffer wraps around.

Appendix Project 2 Stimulus dialog. Class Slide 92 . All Rights Reserved. © 2005 Microchip Technology Incorporated.

OK. All Rights Reserved. Select Debugger\settings Click on Uart1IO tab. Class Slide 93 . We have UART1 IO configured to go to the output window. © 2005 Microchip Technology Incorporated.Appendix Project 2 We would like to watch the UART1 output and see what the status is as we run the program. Check the Enable Uart1 IO box Select the Radio button for window within the output area.

Pay attention to the watch variables and see the ADRESL data values changing. © 2005 Microchip Technology Incorporated.Appendix Project 2 Let’s reset and run the project again. Class Slide 94 . All Rights Reserved. Eventually the system will either stabilize in the Running or Stopped state.

Now set up some asynchronous stimuli. A pulse on RA1 to raise temperature A pulse on RA2 to lower temperature A pulse on RA3 for Float switch © 2005 Microchip Technology Incorporated. Class Slide 95 .Appendix Project 2 Stop the execution. 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. © 2005 Microchip Technology Incorporated. All Rights Reserved.