Wednesday, September 10, 2025

More Harmony

 

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.

 


Tuesday, September 9, 2025

Serial Sniffer - Part ONE

 

While I was waiting for the tariff things to settle out, I designed another PCB that I have always wanted, but could never find at reasonable price.  An RS-232 serial sniffer.  Now that USB is the standard, these dont really exist.  But for embedded, I still use serial to talk to the BT modules and as a logging port.  So this thing has two Serial to USB converters (FTDI based) and then two more Serial ports that are connected to a PIC processor.  The last two will be used to "sniff" a serial port under test.  Then the PIC will arrange the Tx and Rx data in time order and send either to a custom program or to something like TeraTerm.  It also has Mikroe Click port on it, so I can add other modules down the road.    Probably could have found something close, but this way I get exactly what I want.  

 

Monday, September 8, 2025

Brick Lights ONE - Redo

I finally got around to working on this again.  When I first did it, parts availability just killed it.  There were several parts I could not get, including the processor.   I first discussed this here and then a few months ago here, where I discussed a lot of issues with the firmware. Now that has changed, I went back to it.  I made some changes to make it more closely line up with what else I was doing.

As a recap, this was the first iteration.  It has a larger BT module and individual LED connectors.  Looking at the picture at the top, you see that the LED connectors have been consolidated down to three 2 x 5 connectors, which is what I use on the Brick Buddy 3.  Also I have added a standard power connector.  This allowed the entire PCB to shrink down to a 6 x 7 stud size instead of the 6 x 8.

Once I finished this, I sent it out to FAB at my usual fabricator in China.  This right before all the tariff stuff blew up.  I am sure I was not the only one that was trying to squeeze in under the deadline.  Well the PCB that came back had a short between 3.3VDC and GND.  Not good.  After going back and forth with the vendor, they said they found a place where the tolerances were not met. How they missed it, they never said and how my design software did not flag is also a mystery.  Any way drilling out a via fixed the issue.


It required that I put a jumper wire in to power up the section that the drilled out via cut off.  So went on and slowly assembled it one section at a time.  In the very next section, I found another short this time in a signal to GND.  I was not successful in drilling this via out and I called it quits on those boards. 

So I started looking at US sources, the only one that came close was OSH Park.  But that is 3 PCBs.  So I waited to see how this whole tariff thing was going to play out.  The downside to OSH Park is that they do not want inner power planes in negative.  Which has been the standard for years.  I guess toomany instances where the fabricator thinks it is an inner signal layer and does it as a positive.  I redid the inner power planes as signal planes and polygon pours for the power/ground.  We shall see how this works.

Finally it looked like the tariff stuff settled enough, I went ahead and ordered new boards using the signal layers instead of the power layers.

 


 

Friday, September 5, 2025

Lighting Train Platforms

 

I have three types of platforms.  The standard German Railway platform with tilted cover.  On one side it is for passengers and runs most of the length of the passenger platform.  On the other side is a short one used mostly for cargo as it is on a short track.  The last type is the train shed, there are three of them that run down the middle of the picture.

I am using these 5VDC strip LEDs in cool blue.  I will cut them up individually and apply super glue to help hold them in place.  I have found as these heat up, the adhesive on them tends to give out. 

 

Here they are lighted.

I use a 2mm stainless steel pipe to run the wires down from ceiling and through the floor.  This looks like conduit and hides the wire quite well.  The pipe is glued to the post at the top using super glue. From the LED strips I use 36 gauge wire to run through the pipe and underneath platform/shed.

On the bottom side I used hot glue to hold the pipe in place and at the correct depth so that wire has clearance to come out.

Here is what the finished bottom looks like. The small 36 gauge wire goes down the pipe and then is connected to 30 gauge wire to run through the table top.  It will be connected to 28 gauge wire to make the final run to the LED lighting controller. Trying to use the smallest gauge wire only where it is needed.  That way I do not introduce to much wire resistance.

Here is another view of a platform top and how the LED strips are connected.  You can see the 36 gauge wire enter the the 2mm pipe.

This is just another view of the 2mm pipe.  I used the tape to hold it in place while the hot glue on the bottom and the super glue at the top setup.

The final result.