Before getting here, there was Kaos again.
This all started with the Light Buddy 2 firmware development. When I did this first time, there were several functions that were never quite finished. In particular the three digital inputs and the analog input. The digital inputs I had done on the Brick Buddy 3, so that was just a matter of linking in some common code and setting up interrupts. That went as expected. The analog port is connected to the ADC in the PIC32MX270. While I have done many of these ADC implementations in the past. The ADC modules in PIC micros, continue to evolve. In particular, lots of hardware implementation of what used to be firmware. This is good, but can be bad also.
After I got all of the components installed, I set the input to the port at 3.33VDC. Here is the schematic. The input is pin 2 on J19.
This is setup to cut any voltage by 50%, thus if 5VDC accidently gets connected, the maximum voltage at the OPAMP input will be 2.5VDC. As added insurance, there are clamping diodes to keep the voltage below 3.33VDC and above GND. There is a basic low pass filter on the output to keep any jitter to a minimum. We will not be looking at high frequency inputs 😉. I check the inputs and outputs with a meter, On the left side of R36 the voltage is 3.33VDC. On the right side of R36 the voltage is 1.66VDC. On the left side of R38 the voltage is 1.66VDC. So far everything is good.
Well as expected, nothing showed up in the ADC. My go to here is the IOview in the MPLAB debugger. When I look at the ADC, it appears it is not even installed in the PIC32. Trying to change any bit in the ADC was not possible. I could not even turn it on. Many hours go by with no success either in an a Web search or playing with registers. Then I saw a register called PMD1. When you search the data sheet, mostly what you get is a reference to Parallel Master Port Data. Eventually you find Peripheral Module Disable registers.
Harmony set these registers to disable the ADC. So I must have not told it I wanted to use the ADC. Though some of the firmware for the ADC was installed. In the process of restarting this project and setting up a new computer I either lost the Harmony configuration file or corrupted it. I also moved this from Version 206 to Ver 3. So now ADC is showing input, success. Well..................
Except what it is showing is 1.88VDC. The left side of R38 is still showing 1.65VDC, so something is messing with the output. First thought would have been the JTAG/PICKit pins, since they can be moved on this PIC32. But that was not it. With the PIC32, Microchip went
a different way with the data sheets. The part specific data sheet
has limited info on the part, you have to dig out the PIC32 master
datasheet, which is surprisingly hard to find on their web site
directly. And it is done is sections, so I have been downloading
these as I need them.
Buried in the Input Change Notification section of I/O pins are
these little nuggets of info
It appears this applies to Analog inputs as well. Because once I made sure the pullup and pull down on RA0 was off, it worked as expected and I got 511 as the ADC count, which is what I would expect. I also got burned by Harmony again, because it's generated code is what set these registers, not sure how it determined what to do. But going forward I am going to be setting all the pin registers (TRIS, CNPD, CNPU, ANSEL) individually so I can see them, instead of just loading the register with a hex number. I do this for all the PIC18F processors now.
One final note that made this harder. Using the IOView in the debugger these SFRs,CNFD or CNPU, were shown. So that never triggered my thinking to look for that. Plus no one else seems to have run into this problem, since I could not find anything on the Web about it.
Onto installing the RN4871.