This code example contains the code and analog simulation models for the upcoming video "Comparing Simulation to Reality with PIC18F56Q71". This video will compare an analog circuit simulation to the performance of the real device.
See Mindi Model Installation for guidance.
- MPLAB® X IDE v6.0.5 or newer
- MPLAB XC8 v2.41.0 or newer
- MPLAB Code Configurator (MCC)
- PIC18F-Q_DFP v1.16.368 or newer
- PIC18F56Q71 Curiosity Nano
- Oscilloscope
- 10x Oscilloscope Probe (with hook adapter)
- Function Generator
- BNC T-Junction (female to 2x male)
- BNC-BNC Cable (female to female)
- BNC (female) to Mini-Hooks Cable
Warning: Do not apply voltages outside of the absolute maximum ratings to the I/O of the microcontroller. This may cause permanent damage to the device, the Curiosity Nano, and/or the connected computer!
Note: These instructions assume the nano has been programmed. If it has not, make the sure the Curiosity Nano can be connected to a computer for programming after all cables are attached.
Set up the function generator waveform output. The configured waveform should always remain within the absolute maximum ratings of the microcontroller. (By default, the Curiosity Nano runs at 3.3V.)
For the video, the following waveform settings were used:
Setting | Value |
---|---|
Waveform | Sine |
Frequency | 1 kHz |
Amplitude | 1 Vpp |
Offset | 500 mV |
Load | Hi-Z |
With the output OFF, connect the function generator output to the BNC T-Junction. Then, use a BNC-BNC cable to connect one side of the T-junction to your oscilloscope. After connecting, make sure this oscilloscope channel is set to 1x mode with 1MΩ termination.
Next, use the BNC to Mini-Hooks cable to connect from the other side of the T-junction to the Curiosity Nano. Connect the ground hook to a GND point or pin, and connect the signal to RB1. Then, connect your 10x oscilloscope probe to RA1 on the Curiosity Nano. (This oscilloscope input should also be set to 1MΩ termination.)
For the oscilloscope ground, connect to a ground point or pin on the nano. The gold-plated mounting holes on the USB-side can be used for grounding, be beware of any electronic components nearby. Alternatively, a female-to-male wire can be used on a ground pin for a suitable connection.
If the nano has been programmed, plug the nano into any USB power supply or port. Then, enable the output of the function generator.
If the nano has not been programmed, connect the nano to a computer and perform Drag-and-Drop programming, which is described below. (Alternatively, you can compile from source and program in MPLAB X IDE).
- On the Github page for this example, go to the Releases section on the right-side of the screen.
- Download and unzip the hex files for the example.
- Select one of the provided hex files and drag-and-drop the file over the Curiosity Nano icon in the File Explorer. (Both hex files will function identically on the device, the difference is in memory usage.)
- If programming is successful, the yellow LED should start blinking.
Pin | Description |
---|---|
RA1 | OPAMP Output (to oscilloscope) |
RB1 | Analog Input (from function generator) |
RC7 | Blinking LED Indicator |
- Download and install MPLAB Mindi.
- Download the Mindi model for the PIC18F56Q71 family of microcontrollers.
- Drag and drop the model file into the Command Shell of Mindi.
- There will be a prompt to install the model.
- This model can now be found within Mindi.
This example implements a simple non-inverting operational amplifier with a gain of 2, as shown below. Resistor values are approximate values.
To compare, a Mindi schematic of this same configuration is provided in this repository.
This example provides the source code and documentation for the video.