mirror of https://github.com/rusefi/bldc.git
BBSHD: Add DAC support
Signed-off-by: Marcos Chaparro <mchaparro@powerdesigns.ca>
This commit is contained in:
parent
278f767854
commit
c821710d49
|
@ -28,6 +28,8 @@
|
|||
// Variables
|
||||
static volatile bool i2c_running = false;
|
||||
|
||||
void hw_luna_bbshd_setup_dac(void);
|
||||
|
||||
// I2C configuration
|
||||
static const I2CConfig i2cfg = {
|
||||
OPMODE_I2C,
|
||||
|
@ -99,7 +101,11 @@ void hw_init_gpio(void) {
|
|||
palSetPadMode(GPIOA, 1, PAL_MODE_INPUT_ANALOG);
|
||||
palSetPadMode(GPIOA, 2, PAL_MODE_INPUT_ANALOG);
|
||||
palSetPadMode(GPIOA, 3, PAL_MODE_INPUT_ANALOG);
|
||||
#ifdef HW_BBSHD_USE_DAC
|
||||
hw_luna_bbshd_setup_dac();
|
||||
#else
|
||||
palSetPadMode(GPIOA, 5, PAL_MODE_INPUT_ANALOG);
|
||||
#endif
|
||||
palSetPadMode(GPIOA, 6, PAL_MODE_INPUT_ANALOG);
|
||||
|
||||
palSetPadMode(GPIOB, 0, PAL_MODE_INPUT_ANALOG);
|
||||
|
@ -243,3 +249,30 @@ void hw_try_restore_i2c(void) {
|
|||
i2cReleaseBus(&HW_I2C_DEV);
|
||||
}
|
||||
}
|
||||
|
||||
void hw_luna_bbshd_setup_dac(void) {
|
||||
// GPIOA clock enable
|
||||
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
|
||||
|
||||
// DAC Periph clock enable
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);
|
||||
|
||||
// DAC channel 1 & 2 (DAC_OUT1 = PA.4)(DAC_OUT2 = PA.5) configuration
|
||||
palSetPadMode(GPIOA, 4, PAL_MODE_INPUT_ANALOG);
|
||||
palSetPadMode(GPIOA, 5, PAL_MODE_INPUT_ANALOG);
|
||||
|
||||
// Enable both DAC channels with output buffer disabled to achieve rail-to-rail output
|
||||
DAC->CR |= DAC_CR_EN1 | DAC_CR_BOFF1 | DAC_CR_EN2 | DAC_CR_BOFF2;
|
||||
|
||||
// Set DAC channels at 1.65V
|
||||
hw_luna_bbshd_DAC1_setdata(0x800);
|
||||
hw_luna_bbshd_DAC2_setdata(0x800);
|
||||
}
|
||||
|
||||
void hw_luna_bbshd_DAC1_setdata(uint16_t data) {
|
||||
DAC->DHR12R1 = data;
|
||||
}
|
||||
|
||||
void hw_luna_bbshd_DAC2_setdata(uint16_t data) {
|
||||
DAC->DHR12R2 = data;
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#define HW_HAS_PHASE_SHUNTS
|
||||
#define HW_HAS_GATE_DRIVER_SUPPLY_MONITOR
|
||||
#define HW_USE_BRK
|
||||
#define HW_BBSHD_USE_DAC
|
||||
|
||||
// Macros
|
||||
#define LED_GREEN_GPIO GPIOB
|
||||
|
@ -245,5 +246,7 @@
|
|||
#define HW_GATE_DRIVER_SUPPLY_MAX_VOLTAGE 14.0
|
||||
|
||||
// HW-specific functions
|
||||
void hw_luna_bbshd_DAC1_setdata(uint16_t data);
|
||||
void hw_luna_bbshd_DAC2_setdata(uint16_t data);
|
||||
|
||||
#endif /* HW_LUNA_BBSHD_H_ */
|
||||
|
|
Loading…
Reference in New Issue