Real time microcontroller applications, such as digital power supplies, motor controllers, and others that utilize one or several real time digital control loops generally can’t be efficiently debugged using LEDs, single-stepping, setting breakpoints, and other traditional programming techniques. In the process of developing a real time system it is often necessary to change a variable on the fly while observing changes in some other variable, also in real time. Microchip MPLAB X and MPLAB IDE have a tool called DMCI (Data Monitor and Control Interface) allowing to do what the name suggests when used in combination with dsPIC and PIC24 micros. I am a big fan of new “enhanced mid range” PIC16 micros and I always wanted to have similar tool to use with these chips. Some time ago I started porting dsPIC RTDM (Real Time Data Monitor, used to communicate with DMCI) protocol implementation to PIC16 and this short article is the announcement of the first working implementation of the protocol.
The title video (expand it to full-screen and switch the resolution to 1080 to see numbers better) demonstrates PIC16F1509 MCU reading its internal fixed voltage reference (FVR). A plot on the right shows, in near real time, last 128 ADC conversions collected into a buffer. A slider on the left allows me to modify sampling delay of the ADC and you can see the difference in conversion when I change this delay from 50 to 20 microseconds. A FVR is high-impedance source and the effect of sampling too fast can be clearly seen. The output is free running, similar to free running oscilloscope timebase; with little extra effort, reads and writes can be synchronized, if desired – see Microchip code examples CE155, CE455 for details.
It should be noted that PIC16 is a very small micro and no amount of clever coding will change that. The RTDM overhead will likely constrain the use of RTDM to test cases rather than real projects. Still, ability to change and read MCU memory on the fly is very useful while testing implementation of digital filters or PID loops.
The C code used to produce the demo along with DMCI config file is available on GitHub. It will run on PIC16F1509 with external 16MHz crystal, other necessary connections being a decoupling capacitor on VCC and a serial connection to a PC running MPLAB X. All software versions are current at the time of writing.
The detailed documentation of RTDM implementation will be posted in several weeks (or so I hope). To increase speed and reduce code size I will be replacing chunks of C code with assembly so if you don’t like assembly, use github commits made earlier than the timestamp of this article. In the mean time, much can be learned from the code itself and developers already familiar with DMCI for dsPIC will have no difficulties using the code as-is.
Please try this code and let me know how it worked for you. Comments can be left in a my Google Plus community or in the “Issues” section of the GitHub repo. You can also use the comment section of the article or by contacting me using one of the e-mails from the “About” section of the site.