Understanding Stimulus Input Interaction

Besides executing instructions, the simulator also models many of the peripherals on the PIC device, and uses stimulus to model the application circuit external to the PIC device. On an actual application board, the instructions, peripherals and external circuit inputs all happen simultaneously. However, the simulator can only perform one operation at a time. The simulator performs these operations in the following order:

  1. 1.The current instruction is executed.
  2. 2.The peripherals are updated.
  3. 3.Stimulus is executed.

This sequential behavior can sometimes lead to surprising results in the simulator. For example, the current instruction, a peripheral, and stimulus could all store a value to the same SFR in the same instruction cycle. In this case the last operation in the sequence, the value written by stimulus, would be the value in the SFR at the end of the instruction cycle. It is important to understand that all three “writes” to the SFR will have occurred however. If the instruction write triggers an interrupt for example, the interrupt will indeed occur, even though the interrupting bit was ultimately cleared by the stimulus operation.

Be Aware of This:

In addition to modeling the core processor, memories and SFRs of the PIC device, the simulator also models the device pins.

Stimulus allows users to inject values to both pins and to SFRs. This can lead to some confusion as port register fields and port pins usually have the same name, for example, RB0 and PortB.RB0.

Stimulus requires that port register fields use the form PortName.FieldName to distinguish the port field from the port pin. For example:

When injecting to a pin, the simulator considers it to be the same as the application circuit driving a voltage to the pin. When injecting to the PORT register, the simulator considers it to be the same as using the PIC software to write to the port register. Injecting to a pin models an input to the PIC device. Injecting to the PORT register models an output from the PIC.

It is important to remember that the type of injection results in a change to the PORT register depending on many factors such as the state of the related TRIS register, the analog versus digital state of the pin, etc.