PIC16LF15313 PWM LED controller  - Page 1
Forum section: electronics / projects

author: ali6x944
author_rank: Frequent Contributor
timestamp: November 22, 2018, 05:25:43 pm
content: 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/Inand they came out roughly like this using a Peukert number (n) equal to 0.7:Ni-Cd:T=0.7/0.150.7T=2.6413999098063 hoursT=159 minutes approx.Li-Ion:T=3700/0.150.7*Note: 3700mAh came from the fact that the cells are in parallelT=13.961685237547 hoursT=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 conveniencehowever, I haven't been so successful with my main code,Code:**Generated Main Source FileCompany:Microchip Technology Inc.File Name:main.cSummary:This is the main file generated using PIC10 / PIC12 / PIC16 / PIC18 MCUsDescription: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.2Device : PIC16LF15313Driver Version : 2.00*/#include "mcc_generated_files/mcc.h"/*Main application*/void main(void){// initialize the deviceSYSTEM_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

author: Siwastaja
author_rank: Super Contributor
timestamp: November 22, 2018, 09:40:01 pm
content: 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.

author: ali6x944
author_rank: Frequent Contributor
timestamp: November 23, 2018, 05:08:40 am
content: @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 parallelT=24.66666666666 hoursT=1480 minutes approx.

author: Siwastaja
author_rank: Super Contributor
timestamp: November 23, 2018, 07:08:03 am
content: 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 additionto Peukert effect and other charge transfer inefficiencies.