Showing posts with label PIC18F46K40. Show all posts
Showing posts with label PIC18F46K40. Show all posts

Thursday, March 16, 2023

Solar Shed Update


 

A quick update on the Solar Shed progress.  The snow has melted and there is some sun.  I have not been formerly taking down readings, but in general the battery has charged to slight over 14VDC on it at the day and about 13.8VDC in the morning.  Which is comparable to what I saw on the bench.

Moving to the real world is always going to bring on new issues.  What problems did I have, well 😛

  • For the switch that turns on the LED Lighting, for some reason the weak pullups on that input was off.  The overhead LED  lights would go on and off randomly.  I was never a fan of those weak pullups, not sure why I did not just put a 10K or 100K pullup there.  Space and cost were not a driving factor.
  • Next this switch does not wake up the PIC.  When is the PIC sleeping, at night .  When do I need the light, at night.  It is a simple fix, but I am waiting to gather more changes before fixing this.
  • I had added a relay for selecting power source for PIC and etc, from either the battery or the solar panel.  I implemented the logic to use the Solar Panel as the power source whenever it is above about 8VDC.  But forgot to change the TRIS register for the drivers to an output.  No wonder I could not drive the relay to change the source.  Now as long as there is sufficient solar panel voltage, that powers the PIC and etc.
  • All of the conversion constants moved a little, again.  1% resistors are nice, but they are still only 1% accurate.  Another change is to add an OLED screen that shows the ADC count instead of a calculated voltage.  Maybe that will help refine the conversion chart I showed earlier.
  • The 7.5F supper cap took over 2 mins to charge the first time.  I thought there was a short somewhere since the voltage would not rise.  Then I remembered that an uncharged cap is a short. 

I have been thinking of a good test for the super cap.  What I am thinking now is around 8PM disconnect the battery.  The sun will be down, so no solar power.  Then before the sun lights up the solar panel, check if the PIC is still in sleep mode.  One way is to press one of the buttons that will illuminate on the LEDs.  It is a left over debug routine, that is actually quite useful.  The other is to measure the voltage at the Suoer Cap and see if it is providing sufficient voltage.  Then this test needs to be repeated without the OLED installed.  

The process continues.

 

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.