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.15
0.7T=2.6413999098063 hours
T=159 minutes approx.
Li-Ion:
T=3700/0.15
0.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

however, I haven't been so successful with my main code,
**
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