908 Sim

96
© 2005 Microchip Technology Incorporated. All Rights Reserved. Slide 1 SIM 908 Using the MPLAB ® Simulator and Stimulus

Transcript of 908 Sim

Page 1: 908 Sim

© 2005 Microchip Technology Incorporated. All Rights Reserved. Slide 1

SIM 908

Using the MPLAB® Simulator and Stimulus

Page 2: 908 Sim

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

Page 3: 908 Sim

© 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

Page 4: 908 Sim

© 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

Page 5: 908 Sim

© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 5

Simulators

Stimulus Control Language (SCL) forStimulus

Execution Trace now has Filter in/outcapability

Page 6: 908 Sim

© 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!!

Page 7: 908 Sim

© 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

Page 8: 908 Sim

© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 8

UART1 IO with Printf

Page 9: 908 Sim

© 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

Page 10: 908 Sim

© 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

Page 11: 908 Sim

© 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

Page 12: 908 Sim

© 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

Page 13: 908 Sim

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

Page 14: 908 Sim

© 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

Page 15: 908 Sim

© 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

Page 16: 908 Sim

© 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

Page 17: 908 Sim

© 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

Page 18: 908 Sim

© 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

Page 19: 908 Sim

© 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

Page 20: 908 Sim

© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 20

Switch Inputs Complete

111

Page 21: 908 Sim

© 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

Page 22: 908 Sim

© 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

Page 23: 908 Sim

© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 23

UART1 IO Complete

Settings

Output

222

Page 24: 908 Sim

© 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

Page 25: 908 Sim

© 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

Page 26: 908 Sim

© 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

Page 27: 908 Sim

© 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

Page 28: 908 Sim

© 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

Page 29: 908 Sim

© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 29

Synchronous Stimulus

Getting started Need toGenerate theSCL code toperform all thestimulationrequired

CreateWorkbook

333

Page 30: 908 Sim

© 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

Page 31: 908 Sim

© 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

Page 32: 908 Sim

© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 32

Temperature Injection Complete

333

Page 33: 908 Sim

© 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

Page 34: 908 Sim

© 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

Page 35: 908 Sim

© 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

Page 36: 908 Sim

© 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

Page 37: 908 Sim

© 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

Page 38: 908 Sim

© 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

Page 39: 908 Sim

© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 39

Monitoring PORTC Complete

444

Page 40: 908 Sim

© 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

Page 41: 908 Sim

© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 41

Duration TestingSet the Asynchronous stimulus to occur Synchronously using large time units

Page 42: 908 Sim

© 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

Page 43: 908 Sim

© 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

Page 44: 908 Sim

© 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

Page 45: 908 Sim

© 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

Page 46: 908 Sim

© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 46

Trace Buffer with Source View

Page 47: 908 Sim

© 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

Page 48: 908 Sim

© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 48

Logic Analyzer / Simple TriggerMenu item View>Simulator Logic AnalyzerSimpleTriggerdefinitions

Displaypropertybuttons

Zoom

Cursors

Page 49: 908 Sim

© 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

Page 50: 908 Sim

© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 50

Logic Analyzer / Simple TriggerNo data lost whenswitchingchannels

Trigger setto PC

Time base

Page 51: 908 Sim

© 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

Page 52: 908 Sim

© 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

Page 53: 908 Sim

© 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

Page 54: 908 Sim

© 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

Page 55: 908 Sim

© 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

Page 56: 908 Sim

© 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

Page 57: 908 Sim

© 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

Page 58: 908 Sim

© 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

Page 59: 908 Sim

© 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

Page 60: 908 Sim

© 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

Page 61: 908 Sim

© 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

Page 62: 908 Sim

© 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

Page 63: 908 Sim

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

Page 64: 908 Sim

© 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

Page 65: 908 Sim

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

Page 66: 908 Sim

© 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

Page 67: 908 Sim

© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 67

Advanced Pin/Register

Defined conditions populate selection.

Conditions

Sample Workbook

Page 68: 908 Sim

© 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

Page 69: 908 Sim

© 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

Page 70: 908 Sim

© 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.…

Page 71: 908 Sim

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

Page 72: 908 Sim

© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 72

Duration Testing ExampleAdvanced Pin / Register

How can we make the pins pulse?

Page 73: 908 Sim

© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 73

Duration Testing ExampleAdd 2 additional conditions, testing themselves.

Page 74: 908 Sim

© 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

Page 75: 908 Sim

© 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

Page 76: 908 Sim

© 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

Page 77: 908 Sim

© 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

Page 78: 908 Sim

© 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

Page 79: 908 Sim

© 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)

Page 80: 908 Sim

© 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

Page 81: 908 Sim

© 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

Page 82: 908 Sim

© 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

Page 83: 908 Sim

© 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

Page 84: 908 Sim

© 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

Page 85: 908 Sim

© 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

Page 86: 908 Sim

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

Page 87: 908 Sim

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

Page 88: 908 Sim

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

Page 89: 908 Sim

© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 89

Appendix Project 2

Stimulus dialog.

Page 90: 908 Sim

© 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

Page 91: 908 Sim

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

Page 92: 908 Sim

© 2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 92

Appendix Project 2

Stimulus dialog.

Page 93: 908 Sim

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

Page 94: 908 Sim

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

Page 95: 908 Sim

© 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

Page 96: 908 Sim

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