Showing posts with label PIC16F18426. Show all posts
Showing posts with label PIC16F18426. Show all posts

Tuesday, February 7, 2023

LIght Buddy 2 - The Build Part 2

 


 

After spending the AM looking into this, I finally found the problem.  It is and isn't my new PCB.  Above is a photo of the setup.

The absolute source of the issue is the USB battery.  But it is only doing what it was designed to do.  All USB batteries have a minimal current flow cutoff circuit designed into them with a timeout delay.   When the current drops below a preset limit, the battery turns off after the delay.  This minimizes the self discharge rate.  The silver battery in the picture is the one I use for development because it seemed to have a very low cutoff, as in it doesnt turn of as long as something is plugged in.  The LED lights indicating current charge level never went out.  Other USB batteries I have require at least two devices connected with motors and LEDs active, to stay on.  And when they shut off, they shut off completely.  But when I connected the Analog Discovery to the PCB, I found this.

Sometimes the dropout is deeper,  down to just under 2VDC and varies in time from this to about 20ms.  It also happens every 27-28 seconds, which is probably the batteries timeout.  When I switched the power source to a wall charger, all of this went away and the debugger worked without failure for over 30 minutes.  Final test was to add a 100 OHM resistor load to the USB battery using the USB power connector (PCB with red and white punch down blocks on it).  Worked the same as the wall charger.  Removing the 100 ohm resistor and it reverts back to resetting every 27-28 seconds.  

My PCB just did not draw enough current to keep the battery happy.  The USB battery would start to shutdown the voltage, the PCB would start to draw more current as the voltage decreased.  This increase in current was just enough to restart the battery.  Rinse and repeat.
 

Monday, February 6, 2023

MIcrochip PICKIT 4 Not the Problem


I use the Tag-Connect 6 pin connector with Pogo Pins.  Very small footprint.  It appears that the one I have been using for a long while is now flaky, which is why the PICKIT 4 would not connect.  I had another one, but it only had an RJ-11 connector, so I went digging for my ICD3.  Fortunately the ICD3 will do at least two of the four processors I have chosen.  So I thought I would look at buying an ICD4, just to be current.  Well it is EOL, happened back in late September.  The forums seem to indicate they could not build any more, no parts.  In particular no FPGAs are available at an acceptable price.  So that leaves an ICE4 @ $1800 or PICkit4 which I have.  I just might have to buy another PICKIT 4 for insurance purposes.  I did look on Ebay for an ICD4, none to be found and the Asian market wants $1950.  Digikey, Mouser, Newark, etc have all pulled the listing as obsolete.  The Microchip website claims they will continue to update the programmer.  This has only solved my connection problem, the BOR problem still exists as does the debugger resetting when in debug mode.

For older PICs, theICD3 and PICKIT 3 are adequate, not as many breakpoints, but otherwise mostly equivalent.   ICD3 and PICkit3 are not getting any new PICs added to them, so these two will only be the older PICs going forward.  Ends up being the two most likely candidates, PIC16F18326 and PIC16F18426, are old enough that ICD3 and PICkit3 will work on them.  The only issue that will push me to the other two PICs (PIC18F06Q40 and PIC18F06Q41) will be execution speed.  The PIC16F runs at 32MHz and the PIC18F runs at 64MHz.  PIC power is not the issue here, with 6 LEDs running at 25mA each. The power difference is 3mA vs 13mA.  So 10mA increase which leads to 153mA vs 163mA in total power, 6.5%.  I can live with that.  And if the LEDs use less current, say 5mA each,  Then its 33mA vs 43mA, 30% increase.  But the total power is down 73%.  All good.

Tomorrow I am going to try and track down the Brown Out Reset issue, because now I am convinced that is also resetting the PICkit/ICD in debug mode.



Friday, February 3, 2023

Light Buddy 2 - Build Part 1

 

Part of the development time was me copying code from the PIC32 project and not getting all the code.   Then there was a mismatch in the com protocol between the PC and the PIC that had to be fixed. Again, all for the good as I develop a lot more consistent interface and infrastructure code across all of my projects.

When I moved to the PCB two things started happening that were not present on the Microchip Curiosity Development Board.  I could not buy PIC16F18326 parts and had to settle for the LF version.  Should be NO big deal, though it did force the LDO decision to a 3.3VDC version.  First every few seconds the Brown out Reset would fire.  Added code to print out the the registers that tell you what caused the reset, so I know that was it.   Once I disabled BOR, that quit happening.  But now I dont know if what the PIC was seeing is not causing other issues.  

Second the PICKIT 4 is unreliable, not sure why yet.Part of it was a poor connection to the board.  I fixed that, but it will still reset it self after a few seconds.  This is probably related to the BOR issue, just not sure how to debug this, especially if the drop out is very narrow.  Also had to upgrade XC8 and MPLAB X to 5.5, which means the 64bit version.  But as the picture shows I moved to an ICD3 to continue working.

While this PIC runs at 32MHZ max, I am pushing it when running all six LEDs in full feature mode.  I can tell the service loop is not getting around as fast by the way the LEDs react.  It may be OK, I just need more time to refine the loop.  The loop is every 100msec and that may not be enough time to service 6 LEDs.  Also the free compiler does not do a great job on speed optimization.

As an aside, several people have suggested using switches to select the LED modes.  I passed on the switches for now.  The serial port makes it much easier to develop the lighting features and provides a console feature for printf.  Though I had to finish the PC program first before I could get started on the PIC firmware.  Every time I add new features to this Windows software, the whole structure of the program slightly mutates, thus more testing for older features to make sure I did not break them.   The software is getting more structured and easier to modify, just takes time.

Wednesday, February 1, 2023

Light Buddy 2 -The PCB

I received the REV 1 PCBs.  As you can see, they are exactly the size I wanted.  This picture below shows the PCB in the base of Power Generator design I am working on.  I had to extend the height with a 3 x 3 Modified Facet Brick.  That should give all the height I need.  Will probably turn the PCB over and attached the round plates and then mount the PCB to the round plate.  I can always add more 1 x 1 round plates to increase any spacing I need.  So far I am very happy with this.


In the mean time I have been working on the software.  Here I am using a Microchip Curiosity LPC Development board (P/N DM164137) with a PIC16F18326.

Most of the code came together rather quickly.  As I mentioned in the previous posts, this PCB can use 4 different PICs (PIC16F18326, PIC16F18426, PIC18F06Q40 or PIC18F06Q40).  My recent experience with lack of availability drove me to this.  But I wanted one piece of firmware.  Thus I have been experiencing the joy of #IFDEF.......#ENDIF.  I have actually spent quite a bit time with the development board and two of the PICs building the app.  Since these 4 PICs span a few years of introduction, the consistency on the peripheral naming is not great.   I finally have the first two in the above list working at the 95% completion point, the other two are about at the %60 point.  But the last two in the above list should come up quickly since most of the infrastructure is there.  I will have to move to a newer XC8 compiler and newer version of MPLAB X, though to finish up with those newer PICs.

Just as an aside, sometime in the last few years, Tech Writing at Microchip under went some changes.  The datasheets are laid out a little differently now.  I am using PICs that have dedicated PWM controllers in addition to the normal CCP/PWM modules.  On the PICs the CCPs are numbered  1 to 4 like normal.  But the PWMs are number 5&6 on one PIC and 6&7 on another.  The Timers names are different as are the UARTs.  I ended  up with lots of #IFDEF to handle this, including an additional system type 'h' file, because there was some circular reference driving the compiler to spit all kinds of weird errors.

Since this is an old fashion RS232 interface, I had to resurrect some very old code.  For all of my PC LEGO control, I am trying to use one windows APP.  In the USB HID world this proved to be quite easy since identification is built into the USB HID protocol.  The WIN APP then just determines who just connected and adjust accordingly.  Well plugging in an RS232 device that stuff doesn't happen.  You have to code it.   Integrating this into the existing code was not hard, just time consuming.  Surprisingly some remnants of old RS232 interfaces were still present in some of the code.  Dont think I have started form scratch in a long time.

I am fairly close to building a few and testing.  While these do not have a remote control feature, in some cases hiding it in something small is advantageous.

I am now wondering if I can make a smaller one😋
 
 

Monday, January 30, 2023

Light Buddy 2 - The Design

 


Here is what the board looks like.  It is very simple, just a fancy way to control 6 LEDs to produce fixed (kind of) lighting effects.  No remote of any kind.

The voltage regulator, U2, will take up 16VDC and produce either 3.3VDC or 5VDC, haven't decided what voltage to run at.  The intended input is VUSB, so if it is 5VDC, it will just follow the input.  J9 is the power input (GND-VUSB-GND to help prevent incorrect connections).

J8 is a standard TTL/CMOS level RS-232 interface.  My intent is to allow the 6 outputs to be programmed in some fashion, TBD.  The problem is anyone who does this will need a RS232 to USB converter.  For me, this not a big deal, for some LEGO users, this may be a bridge to far.   So when you order it, I would program with the desired effects.  The buyer would pick from a selection of choices.  I have also considered a BT module that plugs onto J8 and J9.  Then you would use the Light Buddy Android App to update it.

The remaining parts are six N-FETs to drive the LEDs and protect the processor outputs from excessive current draw.



On the backside, the two circles is where small 1 x 1 round LEGO plates will attach to the PCB (super glue).  This allows the board to be mounted into the LEGO Model.

The processor is either PIC16F18326, PIC16F18346, PIC18F06Q40 or PIC18F06Q41 families.  They come in different memory sizes, I always start with the largest until I figure out how much I really need.

Finally, the absolute bane of my existence, connectors.  All of these are of the 2mm type.  But as you can see they are large compared to the board.  I have used smaller 1mm 2 pin connectors before, but they are very difficult to un-mate.  Everyone complains about them.  Obviously J8 doesn't need to be populated unless you intend on using the RS232 interface.  J9 could be soldered in.  That just leaves J1 for the LEDs.  They also could be soldered in, but that would make working with the LEGO model more difficult.  You should be able to plug in individual 2 pin 2mm male connectors into J1 for each LED.  I keep looking for a solution to this problem, but have not found anything yet.



Thursday, January 26, 2023

Light Buddy 2 - The Need

 


I have been working on a LEGO generator design for the large LEGO display.  I needed at least 5 LEDs.  4 of them generate a pulsating electric thingee, kind of like a lightning effect or an arc welding effect.  I do this with a PWM generator and then randomly change the times and pulse width.  Not perfect but it does a good job.   I needed this to be small and with some new PICs that have multiple PWMs and independent timers, I think I can get this down to a the size of a 2x4 Lego brick (15.5 x 31.25mm), although it is two sided.  The PIC controllers I am looking at are PIC16F18326, PIC16F18426, PIC18F06Q40 and PIC18F06Q41.  These are the large memory versions.  Once the code size is determined, may be able to move to smaller memory versions.  This will just give more flexibility in ordering, considering the state of IC availability has only marginally improved.

The amazing part was that the PCB vendor I am using for PCBs (PCBWAY) is selling  2 layer, 10 pieces for $5 total, $23 in shipping and 24 hour turn if in green, any other color is 5-6 days.  At those prices it is almost not worth wiring a manual proto anymore.  Could build some generic proto boards to play with.  The max size appears to be 100x100mm or just under 4x4".  And if I were to do multiple designs, the cost would be less since they will all fit in a single package.
 

This may be the next LED controller.