Showing posts with label PIC18F4525. Show all posts
Showing posts with label PIC18F4525. Show all posts

Friday, March 10, 2023

Solar Shed - Assembled

It is mostly assembled now.  First step is test the ADC inputs and make sure they are working correctly.  I built this spreadsheet.  

  • Column A is Vcc=3.29VDC and ADC size is 1024 counts
  • Column B is Battery input voltage
  • Column C is Battery voltage at the ADC input
  • Column D is the ADC counts for that voltage
  • Column E is LT1085 voltage at the ADC input (input voltage is from column B)
  • Column F is the ADC counts for that voltage
  • Column H is Solar Panel input voltage
  • Column I is Solar Panel voltage at the ADC input
  • Column J is the ADC counts for that voltage

Finally the three numbers in row 2 (0.2015, 0.2035 and 0.1286) are actual measured voltage ratios of the voltage input and what is present at the ADC input for each input. Even though I used 1% resistors, there is still +/-1% over the marked resistor values.  And to be fully transparent, even though there are unity gain low bandwidth (10KHz) OP-AMPs driving the PIC ADC, the layout probably could have been better.  It is as tight as SMT0805 resistors/capacitors would allow and is surrounded by ground plane.  But not being an Analog Guru, it is probably just OK.  Below the table You can see the layout for the three ADC inputs. (It;s late and my hand is not quite steady, s the picture is a little fuzzy)

 

Then I compared these numbers against what the ADC was reading.  Finally I tweaked the Vcc number a few millivolts to get  a more consistent match of the table values to the actual ADC readings.  During this process I noticed that I had left the weak pullups on the three ADC input pins on.  After turning them off, the readings were much more consistent.

The next issue was going in and out of sleep.  Just needed to make sure that everything I turned on/off before sleep, was turned off/on after coming out of sleep.  So at least on the desk it seems to work as before.  There are a few enhancements and more testing that are needed

  • When the solar voltage is high enough, run the PIC from the solar panel.
  • Install the super cap and test it.
  • Maybe the PIC runs from the solar panel all the time and the battery only powers the LED lighting in the shed.

Ran the system in sleep all night.  Starting battery voltage at 10PM was 13.68VDC.  At 8AM the next morning the voltage was 13.51VDC.  Now in LiFePO battery system this doesnt mean much.  Unless you have a calibrated battery gas gauge IC connected, there is no way to know how much battery life was consumed.   We must remember that a LiFePO battery discharge curve is quite flat until the inflection point.  What is important is the current numbers from the previous post, the system with OLED and in SLEEP, consumed 2.25mA from the battery.  That should be equivalent to 18mA-Hr.  Fully charged (and new) the battery is rated at 9.6A-Hr.  So over night we used about 0.2% of the battery.  

I will be interested to see what the super cap does.  That will be the next test.  Still waiting for the sun to appear and the snow to melt.


 


Monday, March 6, 2023

Solar Shed-Close

 

I am closer to having a working system, but some further "compromises" may still be in order. 😕

The new PIC processor came in.  It did not take long to swap out the PIC18F4525 for the PIC18F46K40.  Went through some configuration issues, but finally got it working.  Since this was a minimal part design, there is no oscillator.  The PIC18F46K40 has an internal Oscillator that runs up to 64MHz.  Nothing I am doing needs that kind of speed.  Thus 8MHz was the compromise speed.  What I did do was up the SPI clock rate to 2MHz.  The MIKROE OLED C will run much faster, but that is good enough.  

Then I started working on the SLEEP routine.  I have not done any very low power work since working on the T-DUST module.  Spent a few minutes reading the data sheet on SLEEP and Watchdog Timers, as well as reviewing what I did in T-DUST.  

On the PIC18F46K40 the way it is implemented on the Solar Shed PCB, nothing runs when it goes to sleep, except the Watchdog Timer (WDT).  And in this configuration, it can only run from one of the low frequency oscillators, whose frequency is about 31KHz.  The WDT has pre-scaler that will give a maximum time of about 256 seconds or a signal about every 4 minutes.

In the main loop, the code will look at the Solar Panel voltage each time through the main loop.  If the voltage is above about 8VDC (subject to change when the system is tested), the code will continue in the main loop.  If it is below this threshold, the PIC will go start the WDT and then go to SLEEP.  When the WDT expires (about 256 seconds), the PIC will wake up.  At this point it will look at the Solar Panel voltage, and if it is above 8VDC, the code will wake up and continue with the main loop, until which time the solar panel voltage falls below 8VDC.  If the solar panel voltage is below 8VDC, the PIC will restart the WDT and go back to sleep.  At this point the SLEEP process starts all over.

I do check to make sure the WDT is the wake up source, if not, then a reset of the entire system is executed.

This led to taking current measurements.  Without making some changes, I can only measure the input to the DC-DC converter that makes the 5VDC, that then is transformed to 3.3VDC by an LDO.  So assuming 100% efficiency in the DC-DC converter, these numbers are the best one would expect.  Reality is they are somewhat worse at 5VDC.

  • Run w/o OLED on  4.5mA @12VDC = 10.8mA @5VDC
  • Run w/ OLED on 12.0mA @12VDC = 28.8mA @5VDC
  • Sleep (OLED is powered but display not on) 2.25mA @12VDC = 5.4mA @5VDC
  • Sleep (OLED module removed) 275uA @5VDC = 600uA @5VDC

There is a 7.5F super cap that is suppose to power the system through the night if the battery is too low.  At 600uA this might happen, but a 5.4mA I have my doubts.  This leaves me with three choices:

  1. Remove the OLED.  It is nice to have to see voltages, but for the 80%+ of the time no one is inside the shed, it serves no purpose.
  2. Do some cutting of traces and install a high side switch on the OLED.  Thus it is only on when voltage display is requested.  Cutting the ground traces will problematic since there is ground plane on both sides of the PCB.  Also not sure there won't be leakage through the SPI and other control pins.  This option is not appealing.😞
  3. Do nothing.  Maybe at 10.8mA, the battery will last long enough to get to the charging opportunity.

So this is a testing processing to see what happens.  Right now it is snowing, so nothing will happen until the sun comes out again.

An interesting note is what happened to the PCB when I removed the PIC18F4525 with the hot air gun and then cleaned the pads with solder wick.  The combination of the two seems to have rubbed off some of the solder mask.  Nothing is critical, but these pictures show the issue.  Not going to complain, paid $5 for five PCBs.  It is a one off.





 

Wednesday, March 1, 2023

Solar Shed - Epic Fail

 

This is very embarrassing.  The new PCB for the Solar Shed has multiple problems and they are just dumb mistakes.  I can't believe I did not catch these.  So here is the revelation of what happened.

Digital vs Analog Inputs

The PIC18F4525 is an older PIC.  During the design process, there was a nagging issue in the back of my mind on how the ADC actually connected to the I/O pins.  Early on in my designing with PIC processors (PIC16F876 and PIC16F877), I was burned by an issue with the ADC.  I did a cursory look at the PIC18F4525 data sheet but could not find anything that was out of the ordinary.  When I was changing the firmware to accommodate the PIC18F4525, I finally found it, but this was after the PCB arrived in hand.

This is an excerpt from the PIC18F4525 data sheet.  This is one of the registers that controls the ADC.  In particular look at Port Configuration Control Bits.  These four bits determine which I/O ports are digital inputs and which are analog inputs.  But you don't have complete freedom.  This is a cascading implementation.  As an example if you need AN5 to be analog, then AN0-AN4 also have to be analog.

As time went along in the development of the PIC18F processors, the Port Configurations Control Bits were expanded inside the ADC registers to have a bit for each input.  Then when more analog features were added and the ADC inputs were expanded to almost every I/O pin, the Analog Select (ANSELx) registers appeared, one for each PORT (A-E) on 44 pin parts.

Well if you have not surmised already, the three inputs that I used are AN5-AN7.  That means the I/O pins AN0-AN4 are also analog inputs.  This translates to RA0=RA3 and RA5.  I did not use RA5 and RA0-RA3 are used for i/O control of the OLED display.  What I should have done was finish the firmware changes for the PIC18F4525.  That way I would have run into this before I submitted the PCB design.

SPI Connections

Next issue is even more embarrassing.  I did not correctly connect the SPI to the OLED.  The PIC18F4525 is before PPS (Peripheral Pin Select) which let you have some flexibility on moving PIC functions to different I/O pins.   As you can see from the schematic snippet below, I built the symbol correctly as RC3-RC5 are labeled with the SPI pins.  I just did not connect the wires.  This is mostly a cut and paste failure.  I copied this circuit from a previous design that used a PIC18F47J50 that had PPS.  Somehow in the process of checking this, it went right by me.

Solutions:

  1. Software fix:  Since I use the ADC every few seconds and the OLED display is strictly user initiated through one of the push buttons, I could change these four bits in ADCON1 to reflect current usage at the time. However there is this warning (shown below) in several places in the data sheet about having analog inputs on a digital input.  And even if I pursue the software fix, the SPI issue will have to be a "cut and jump" approach.

  2. New PCB:  So I only paid $5 for five PCBs and $27 to ship it and 3 other PCB designs.  Total cost was about $12 for the five PCBs.  So I am not into it for a lot of money.  This is just a time factor.  Redo the design, submit and wait for delivery.
  3. New Processor: I was trying to use existing parts I had.  I have other 44 pin TQFPs on hand.  All of them are USB devices and thus have a slightly different pin usage.  Mostly the USB pins and internal regulator that needs a capacitor on the pin.  Not a good choice.  So I started looking at what other PIC18F processors come in a 44 pin TQFP.  The parameter tool on the Microchip website was not as good as it used to be.  It is pushing newer parts that are not what I am looking for.  What I need is a basic 44pin TQFP with PPS.  So I went to Digi-Key and used their search tool.  What popped up was a PIC18F46K40, which is the next FLASH size down from the PIC18F47K40, the part in the HPC Curiosity board this all started from.  The difference is 64K vs 128K FLASH program space.  And it was $2.50 in quantity 1.
     

Where am I, well I am thinking of the PIC18F46K40.  This time I am going to do all the software changes first and make sure the current PCB layout will work.  If that works out, then I will buy two PIC18F46K40s and go from there.  If not, then it may be hacking up the board to make it work.  I only need one.


 

Wednesday, February 22, 2023

Solar Shed Battery Charging

 

 

While I was waiting on the new PCB to come in, I started testing the charging of the battery under real conditions.  What I did was take just the daughter board from the old design (as shown above) and force the path from the solar panel through the LT1085 to the battery.  Then about once a day I recorded the battery voltage to see what was happening.  The data so far is shown here.

 
 
There were some very sunny days and a few slightly clouded days.  In retrospect, I probably should have recorded the sky conditions for the previous period also.  The data shows how the voltage has varied.  As a reminder, the solar panel is only 7.5W and has a max current of about 500mA, under ideal sun conditions.  Given the time of year and the fact that sun does not clear the house next door until after 11AM this time of year, I am not surprised that it is not charging very fast.  Once the house next door is not blocking the sun at anytime, which won't happen until sometime in March, I suspect it will be hard to charge much faster.

I am surprised that there appears to be some discharge during the night.  It is not much and for now I am assuming it is more self discharge due to very cold nights (20-25F).  There might be some sneak current path back into the LT1085 when it is not powered.  I did put in a diode in the new desig to help prevent this.

 






Monday, February 13, 2023

Solar Shed - New Design

 

In my last update, I stated the need to redesign this.  I went through the extra parts I have and started working on a new design that eliminated the Curiosity HPC development board.  Here are the changes that have been made.

  1. Had quite a few PIC18F4525 PIC processors.  Since they had 48K of FLASH memory, that made them a good choice.  The FONT files for the OLED take up to 64K, but they can be trimmed downed to fit in 32K, so this will work just fine.
  2. Changed the LED configuration a little and with a custom PCB I can label them and make them different colors so I can easily tell what is happening.
  3. I added a DC-DC converter circuit that will take either the Solar Panel output or the Battery as input and make 5VDC.  This is the same DC-DC that I used in the Train Light Controller.  I had to buy 20 of them from the Asian after market, so these are essentially free.  
  4. I changed the way the relays work.  While this is hard to read, it is good enough to explain the basics.  The top relay works as before connecting/disconnecting the battery from charging.  The middle relay connects/disconnects the LED lights in the shed.  The bottom relay is new and allows for either the battery or the solar panel to provide power to the DC-DC converter that then powers the PIC circuit.  Also the relays are now powered either by the battery or the solar panel through the LT1085 in a wired OR configuration. 

  5. Finally the PIC is still at 3.3VDC since that is the power of the OLED display.  To provide a quasi battery backup, a large super capacitor (7.5F) is installed between the DC-DC output and the 3,3VDC LDO input.  When the solar panel goes under voltage and the battery is also under voltage, the super cap should power the PIC.  It will be sleeping 90% of the time, waking up every few minutes to check the voltage on the solar panel and the battery, if neither is sufficient it will go back to sleep.

  6. Added two push buttons that will allow me to manually change the relay that charges the battery and the relay selects the power source for the DC-DC converter.  This way if I can make sure the battery is connected/disconnected and the appropriate power source is selected. 
  7. I added four #6-32 holes to make mounting easier.

Need to some final checks, then I can generate the PCB files.  I am working on a few other designs so that I can take advantage of combined shipping.