Author Topic: PIC16LF15313 PWM LED controller  (Read 1056 times)

0 Members and 1 Guest are viewing this topic.

Offline ali6x944Topic starter

  • Frequent Contributor
  • **
  • Posts: 577
  • Country: sa
PIC16LF15313 PWM LED controller
« on: November 22, 2018, 05:25:43 pm »
Hi everybody,
the Fall season is upon us, it is time to make something with LEDs!
so I decided to hack a bunch of mains powered hand-held LED lights that used to have internal SLA batteries...
the batteries are done for it and have seen better days, so I decided to replace it with either A Sanyo UR18650Y battery in a parallel 2-cell pack or a generic Ni-Cd battery pack with 4 cells in series,  I used this equation to figure out the approx. battery life:
T=C/In
and they came out roughly like this using a Peukert number (n) equal to 0.7:
Ni-Cd:
T=0.7/0.150.7
T=2.6413999098063 hours
T=159 minutes approx.

Li-Ion:
T=3700/0.150.7         *Note: 3700mAh came from the fact that the cells are in parallel
T=13.961685237547 hours
T=838 minutes approx.

I did some safety analysis and I think it is sad I have to trade so much battery life for ease of charging, discharging, handling...
honestly, I think it is safer to deal with the Ni-Cd taking into account that Ni-Cds can take a lot of abuse without failing catastrophically...
moving on to the micro, a PIC16LF15313 is used in this project in conjunction with XC8 C compiler v2.00 and MCC v3.0 and I configured all the peripherals using the MCC just for convenience  ;D
however, I haven't been so successful with my main code,
Code: [Select]
**
  Generated Main Source File

  Company:
    Microchip Technology Inc.

  File Name:
    main.c

  Summary:
    This is the main file generated using PIC10 / PIC12 / PIC16 / PIC18 MCUs

  Description:
    This header file provides implementations for driver APIs for all modules selected in the GUI.
    Generation Information :
        Product Revision  :  PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.65.2
        Device            :  PIC16LF15313
        Driver Version    :  2.00
*/


#include "mcc_generated_files/mcc.h"

/*
                         Main application
 */
void main(void)
{
    // initialize the device
    SYSTEM_Initialize();

    // When using interrupts, you need to set the Global and Peripheral Interrupt Enable bits
    // Use the following macros to:

    // Enable the Global Interrupts
    //INTERRUPT_GlobalInterruptEnable();

    // Enable the Peripheral Interrupts
    //INTERRUPT_PeripheralInterruptEnable();

    // Disable the Global Interrupts
    //INTERRUPT_GlobalInterruptDisable();

    // Disable the Peripheral Interrupts
    //INTERRUPT_PeripheralInterruptDisable();

    while (IO_RA1_GetValue()==1)
    {
        ADC_GetConversion(channel_ANA2);
        uint16_t dutyValue = ADC_GetConversionResult();
        if (IO_RA4_GetValue()==1)
        {
            RA5_SetLow();
            PWM4_LoadDutyValue(dutyValue);
        }
        if (IO_RA4_GetValue()==0)
        {
            RA0_SetLow();
            PWM3_LoadDutyValue(dutyValue);
        }
    }
   
}
/**
 End of File
*/

I don't know why the application code doesn't work but I suspect it is due to the ADC_GetConversionResult() not functioning for some reason, I guess...
I would like some enlightenment from you in this project,
thanks a lot for help
 

Offline Siwastaja

  • Super Contributor
  • ***
  • Posts: 8789
  • Country: fi
Re: PIC16LF15313 PWM LED controller
« Reply #1 on: November 22, 2018, 09:40:01 pm »
There is no Peukert effect on li-ion, so the exponent is 1.0. Energy and runtime calculations are really straightforward with the basic units. You may want to leave optional leeway, for example, by not discharging below 10% or so.
« Last Edit: November 22, 2018, 09:43:01 pm by Siwastaja »
 
The following users thanked this post: ali6x944

Offline ali6x944Topic starter

  • Frequent Contributor
  • **
  • Posts: 577
  • Country: sa
Re: PIC16LF15313 PWM LED controller
« Reply #2 on: November 23, 2018, 05:08:40 am »
@Siwastaja dose Li-Ion batteries have any other effects that may reduce the runtime that I shall account for?
so EDIT Li-Ion:
T=3.7/0.15        *Note: 3700mAh came from the fact that the cells are in parallel
T=24.66666666666 hours
T=1480 minutes approx.

 

Offline Siwastaja

  • Super Contributor
  • ***
  • Posts: 8789
  • Country: fi
Re: PIC16LF15313 PWM LED controller
« Reply #3 on: November 23, 2018, 07:08:03 am »
Charge transfer in li-ion is almost perfect. No special effects.

Just ageing (calendar and cycling) which simply reduces capacity, you can assume 2-6%/year and 2-4%/100cycles. Generally 30% capacity drop is considered end-of-life, which tends to happen between 2..15 years depending on how hard the usage conditions are.

If you want to design something really robust, you may want to do the calculations with 60% capacity, so that even with the end-of-life 70% capacity, there is still 10% extra leeway left. Depends how critical your runtime number is.

OTOH, this derating and ageing also applies to most other battery chemistries as well - in addition to Peukert effect and other charge transfer inefficiencies.
 
The following users thanked this post: ali6x944


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf