Skip to content

Commit

Permalink
Major feature implementation: Charging, balancing, precharge, RTCC
Browse files Browse the repository at this point in the history
  • Loading branch information
raphaelchang committed Nov 24, 2016
1 parent 2ed99f0 commit 4e98857
Show file tree
Hide file tree
Showing 32 changed files with 1,000 additions and 185 deletions.
2 changes: 1 addition & 1 deletion ChibiOS_16.1.4/ext/stdperiph_stm32f3/inc/stm32f30x_dma.h
Expand Up @@ -35,7 +35,7 @@
#endif

/* Includes ------------------------------------------------------------------*/
#include "stm32f30x.h"
#include "stm32f3xx.h"

/** @addtogroup STM32F30x_StdPeriph_Driver
* @{
Expand Down
4 changes: 4 additions & 0 deletions ChibiOS_16.1.4/ext/stdperiph_stm32f3/src/stm32f30x_dma.c
Expand Up @@ -73,6 +73,10 @@
/* Includes ------------------------------------------------------------------*/
#include "stm32f30x_dma.h"

#ifndef assert_param
#define assert_param(expr) ((void)0)
#endif

/** @addtogroup STM32F30x_StdPeriph_Driver
* @{
*/
Expand Down
3 changes: 2 additions & 1 deletion ChibiOS_16.1.4/ext/stdperiph_stm32f3/stm32lib.mk
@@ -1,6 +1,7 @@
# STM32F3 STDPERIPH files.
STM32SRC = ${CHIBIOS}/ext/stdperiph_stm32f3/src/stm32f30x_flash.c \
${CHIBIOS}/ext/stdperiph_stm32f3/src/stm32f30x_tim.c \
${CHIBIOS}/ext/stdperiph_stm32f3/src/stm32f30x_rcc.c
${CHIBIOS}/ext/stdperiph_stm32f3/src/stm32f30x_rcc.c \
${CHIBIOS}/ext/stdperiph_stm32f3/src/stm32f30x_dma.c

STM32INC = ${CHIBIOS}/ext/stdperiph_stm32f3/inc
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -122,7 +122,7 @@ CSRC = $(STARTUPSRC) \
$(TESTSRC) \
$(CHIBIOS)/os/hal/lib/streams/memstreams.c \
$(CHIBIOS)/os/hal/lib/streams/chprintf.c \
main.c gpio.c led_rgb.c ltc6803.c comm_usb.c comm_can.c packet.c console.c charger.c adc.c rtcc.c power.c current_monitor.c buzzer.c eeprom.c config.c accessory.c
main.c gpio.c led_rgb.c ltc6803.c comm_usb.c comm_can.c packet.c console.c charger.c analog.c rtcc.c power.c current_monitor.c buzzer.c eeprom.c config.c accessory.c ws2812b.c faults.c

# C++ sources that can be compiled in ARM or THUMB mode depending on the global
# setting.
Expand Down
6 changes: 4 additions & 2 deletions accessory.c
@@ -1,20 +1,22 @@
#include "accessory.h"
#include "hw_conf.h"
#include "power.h"
#include "ws2812b.h"

void accessory_init(void)
{
palSetPadMode(ACC1_GPIO, ACC1_PIN, PAL_MODE_OUTPUT_OPENDRAIN | PAL_STM32_OSPEED_MID1);
palSetPad(ACC1_GPIO, ACC1_PIN);
palSetPadMode(ACC2_GPIO, ACC2_PIN, PAL_MODE_OUTPUT_OPENDRAIN | PAL_STM32_OSPEED_MID1);
palSetPad(ACC2_GPIO, ACC2_PIN);
palSetPadMode(ACC2_GPIO, ACC2_PIN, PAL_MODE_ALTERNATE(6));
ws2812b_init();
}

void accessory_update(void)
{
if (!power_is_shutdown())
{
palClearPad(ACC1_GPIO, ACC1_PIN);
ws2812b_set_all(0x00FF00);
}
else
{
Expand Down
22 changes: 0 additions & 22 deletions adc.c

This file was deleted.

12 changes: 0 additions & 12 deletions adc.h

This file was deleted.

86 changes: 86 additions & 0 deletions analog.c
@@ -0,0 +1,86 @@
#include "analog.h"
#include "hal.h"
#include "hw_conf.h"
#include "faults.h"
#include <math.h>

static const ADCConversionGroup adc3 = {
FALSE,
2,
NULL,
NULL,
0, /* CFGR */
ADC_TR(0, 4095), /* TR1 */
{ /* SMPR[2] */
0,
0
},
{ /* SQR[4] */
ADC_SQR1_SQ1_N(CHG_SENSE_CHANNEL) | ADC_SQR1_SQ2_N(DSG_SENSE_CHANNEL),
0,
0,
0
}
};

static const ADCConversionGroup adc4 = {
FALSE,
1,
NULL,
NULL,
0, /* CFGR */
ADC_TR(0, 4095), /* TR1 */
{ /* SMPR[2] */
0,
0
},
{ /* SQR[4] */
ADC_SQR1_SQ1_N(TEMP_SENSE_CHANNEL),
0,
0,
0
}
};

static volatile uint16_t charger_input_voltage;
static volatile uint16_t thermistor;
static volatile uint16_t discharge_voltage;

void analog_init(void)
{
adcStart(&ADCD3, NULL);
adcStart(&ADCD4, NULL);
adcsample_t samples[2];
adcConvert(&ADCD3, &adc3, samples, 1);
charger_input_voltage = samples[0];
discharge_voltage = samples[1];
}

void analog_update(void)
{
adcsample_t samples3[2];
adcConvert(&ADCD3, &adc3, samples3, 1);
charger_input_voltage = samples3[0];
discharge_voltage = samples3[1];
adcsample_t samples4[1];
adcConvert(&ADCD4, &adc4, samples4, 1);
thermistor = samples4[0];
if (analog_temperature() > 100)
faults_set_fault(FAULT_BOARD_TEMP);
}

float analog_charger_input_voltage(void)
{
return charger_input_voltage / 4095.0 * 3.3 * (39000.0 + 18000.0 + 4700.0) / 4700.0;
}

float analog_temperature(void)
{
return (1.0 / ((logf(((4095.0 * 10000.0) / thermistor - 10000.0) / 10000.0) / 3434.0) + (1.0 / 298.15)) - 273.15);
}

float analog_discharge_voltage(void)
{
return discharge_voltage * (3.3 / 4095.0) * (200000.0 + 100 + 2500 + 10000.0) / 10000.0;

}
12 changes: 12 additions & 0 deletions analog.h
@@ -0,0 +1,12 @@
#ifndef _ANALOG_H_
#define _ANALOG_H_

#include "ch.h"

void analog_init(void);
void analog_update(void);
float analog_charger_input_voltage(void);
float analog_temperature(void);
float analog_discharge_voltage(void);

#endif /* _ANALOG_H_ */

0 comments on commit 4e98857

Please sign in to comment.