EPS

Dependencies:   PowerControl

Dependents:   HEPTA_assembly template HEPTA_GS

Fork of HeptaBattery by Hepta 2

Committer:
umeume
Date:
Wed Aug 23 10:40:53 2017 +0000
Revision:
3:16fd450bcf16
Parent:
2:821f36c03e26
test

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hepta2ume 0:1682fa22a51e 1 #include "HeptaBattery.h"
hepta2ume 0:1682fa22a51e 2 #include "mbed.h"
hepta2ume 0:1682fa22a51e 3
hepta2ume 0:1682fa22a51e 4 HeptaBattery::HeptaBattery(PinName bat, PinName bat_ct) : _bat(bat),_bat_ct(bat_ct)
hepta2ume 0:1682fa22a51e 5 {
hepta2ume 2:821f36c03e26 6 _bat_ct = 1;
hepta2ume 0:1682fa22a51e 7 PHY_PowerDown();//Ethernet PHYchip停止
hepta2ume 0:1682fa22a51e 8 }
hepta2ume 0:1682fa22a51e 9
hepta2ume 0:1682fa22a51e 10 void HeptaBattery::vol(float* bt)
hepta2ume 0:1682fa22a51e 11 {
hepta2ume 0:1682fa22a51e 12 *bt = (_bat.read()*1.431*3.3);//バッテリー電圧読み出し
hepta2ume 0:1682fa22a51e 13 }
hepta2ume 0:1682fa22a51e 14
hepta2ume 0:1682fa22a51e 15 void HeptaBattery::fast_charge()
hepta2ume 0:1682fa22a51e 16 {
hepta2ume 0:1682fa22a51e 17 //Peripheral_PowerDown(0x7DFEDFEE);怪しい
hepta2ume 2:821f36c03e26 18 _bat_ct = 0;
hepta2ume 0:1682fa22a51e 19 }
hepta2ume 0:1682fa22a51e 20
hepta2ume 0:1682fa22a51e 21 void HeptaBattery::vol_u16(char* bt_u16, int *dsize)
hepta2ume 0:1682fa22a51e 22 {
hepta2ume 0:1682fa22a51e 23 unsigned short bt_datas;
hepta2ume 0:1682fa22a51e 24 char bt1[8]= {0x00},bt2[8]= {0x00};
hepta2ume 0:1682fa22a51e 25 bt_datas=_bat.read_u16()>>4;
hepta2ume 0:1682fa22a51e 26 sprintf( bt1, "%02X", (bt_datas >> 8) & 0x0F);
hepta2ume 0:1682fa22a51e 27 sprintf( bt2, "%02X", (bt_datas) & 0xFF);
hepta2ume 0:1682fa22a51e 28 bt_u16[0]=bt1[0];
hepta2ume 0:1682fa22a51e 29 bt_u16[1]=bt1[1];
hepta2ume 0:1682fa22a51e 30 bt_u16[2]=bt2[0];
hepta2ume 0:1682fa22a51e 31 bt_u16[3]=bt2[1];
hepta2ume 0:1682fa22a51e 32 *dsize = 4;
hepta2ume 0:1682fa22a51e 33 }
hepta2ume 0:1682fa22a51e 34
hepta2ume 0:1682fa22a51e 35 void HeptaBattery::power_saving_mode()
hepta2ume 0:1682fa22a51e 36 {
hepta2ume 0:1682fa22a51e 37 float Bat;
hepta2ume 0:1682fa22a51e 38 Bat = _bat.read()*1.431*3.3;
hepta2ume 0:1682fa22a51e 39 //4.2以上
hepta2ume 0:1682fa22a51e 40 if(Bat>=4.2) {
umeume 3:16fd450bcf16 41 _bat_ct = 1;
umeume 3:16fd450bcf16 42 //Peripheral_PowerUp(0xFDFF6FF7);
hepta2ume 0:1682fa22a51e 43 LPC_SC->CCLKCFG = 2;
hepta2ume 0:1682fa22a51e 44 SystemCoreClockUpdate();
hepta2ume 0:1682fa22a51e 45 }
hepta2ume 0:1682fa22a51e 46 //3.7 < Voltage < 4.1
hepta2ume 0:1682fa22a51e 47 else if(Bat<=4.1 && Bat>=3.7) {
umeume 3:16fd450bcf16 48 //Peripheral_PowerUp(0xFDFF6FF7);
hepta2ume 0:1682fa22a51e 49 LPC_SC->CCLKCFG = 2;
hepta2ume 0:1682fa22a51e 50 SystemCoreClockUpdate();
hepta2ume 0:1682fa22a51e 51 _bat_ct = 1;
hepta2ume 0:1682fa22a51e 52 }
hepta2ume 0:1682fa22a51e 53 //3.5V以下
hepta2ume 0:1682fa22a51e 54 else if(Bat<=3.5) {
umeume 3:16fd450bcf16 55 //Peripheral_PowerDown(0x7D7E6DF1);
hepta2ume 0:1682fa22a51e 56 LPC_SC->CCLKCFG = 5;
hepta2ume 0:1682fa22a51e 57 SystemCoreClockUpdate();
umeume 3:16fd450bcf16 58 _bat_ct = 0;
hepta2ume 0:1682fa22a51e 59 }
hepta2ume 0:1682fa22a51e 60
hepta2ume 0:1682fa22a51e 61 }