Adjust pinout and add LED support for HW Rev. B
This commit is contained in:
parent
7a62eb9d11
commit
aea2abc9ea
|
@ -11,32 +11,32 @@ void fan_ctrl_pwm_init(void)
|
||||||
gpio_clear(DCDC_PORT, DCDC_BYPASS_SWITCH_PIN);
|
gpio_clear(DCDC_PORT, DCDC_BYPASS_SWITCH_PIN);
|
||||||
gpio_mode_setup(DCDC_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, DCDC_BYPASS_SWITCH_PIN);
|
gpio_mode_setup(DCDC_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, DCDC_BYPASS_SWITCH_PIN);
|
||||||
|
|
||||||
// *** TIM21 ***
|
// *** TIM2 ***
|
||||||
// Configure channel 1 for PWM
|
// Configure channel 2 for PWM
|
||||||
// Ch1 = charge pump output
|
// Ch1 = charge pump output
|
||||||
|
|
||||||
timer_set_mode(TIM21, TIM_CR1_CKD_CK_INT, TIM_CR1_CMS_EDGE, TIM_CR1_DIR_UP);
|
timer_set_mode(TIM2, TIM_CR1_CKD_CK_INT, TIM_CR1_CMS_EDGE, TIM_CR1_DIR_UP);
|
||||||
|
|
||||||
// set up PWM channel
|
// set up PWM channel
|
||||||
timer_set_oc_mode(TIM21, TIM_OC1, TIM_OCM_PWM1);
|
timer_set_oc_mode(TIM2, TIM_OC2, TIM_OCM_PWM1);
|
||||||
timer_enable_oc_output(TIM21, TIM_OC1);
|
timer_enable_oc_output(TIM2, TIM_OC2);
|
||||||
timer_enable_oc_preload(TIM21, TIM_OC1);
|
timer_enable_oc_preload(TIM2, TIM_OC2);
|
||||||
timer_set_oc_polarity_high(TIM21, TIM_OC1);
|
timer_set_oc_polarity_high(TIM2, TIM_OC2);
|
||||||
|
|
||||||
// prescaler
|
// prescaler
|
||||||
timer_set_prescaler(TIM21, 21 - 1); // Timer runs at 100 kHz
|
timer_set_prescaler(TIM2, 21 - 1); // Timer runs at 100 kHz
|
||||||
|
|
||||||
// auto-reload value
|
// auto-reload value
|
||||||
timer_set_period(TIM21, 100 - 1); // overflow every 100 cycles = 1 kHz
|
timer_set_period(TIM2, 100 - 1); // overflow every 100 cycles = 1 kHz
|
||||||
|
|
||||||
// output compare value
|
// output compare value
|
||||||
timer_set_oc_value(TIM21, TIM_OC1, 0); // No PWM output by default
|
timer_set_oc_value(TIM2, TIM_OC2, 0); // No PWM output by default
|
||||||
|
|
||||||
// only generate interrupt on overflow
|
// only generate interrupt on overflow
|
||||||
timer_update_on_overflow(TIM21);
|
timer_update_on_overflow(TIM2);
|
||||||
|
|
||||||
// enable main output
|
// enable main output
|
||||||
timer_enable_break_main_output(TIM21);
|
timer_enable_break_main_output(TIM2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ void fan_ctrl_pwm_enable(void)
|
||||||
gpio_set_af(FAN_PORT, GPIO_AF0, FAN_PWM_PIN);
|
gpio_set_af(FAN_PORT, GPIO_AF0, FAN_PWM_PIN);
|
||||||
|
|
||||||
// start the PWM timer
|
// start the PWM timer
|
||||||
timer_enable_counter(TIM21);
|
timer_enable_counter(TIM2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -60,8 +60,8 @@ void fan_ctrl_pwm_disable(void)
|
||||||
gpio_clear(DCDC_PORT, DCDC_BYPASS_SWITCH_PIN);
|
gpio_clear(DCDC_PORT, DCDC_BYPASS_SWITCH_PIN);
|
||||||
|
|
||||||
// set PWM value to 0 and stop the counter
|
// set PWM value to 0 and stop the counter
|
||||||
timer_set_oc_value(TIM21, TIM_OC1, 0);
|
timer_set_oc_value(TIM2, TIM_OC2, 0);
|
||||||
timer_disable_counter(TIM21);
|
timer_disable_counter(TIM2);
|
||||||
|
|
||||||
// configure the PWM GPIO as input so the fan runs full speed if powered
|
// configure the PWM GPIO as input so the fan runs full speed if powered
|
||||||
gpio_mode_setup(FAN_PORT, GPIO_MODE_INPUT, GPIO_PUPD_NONE, FAN_PWM_PIN);
|
gpio_mode_setup(FAN_PORT, GPIO_MODE_INPUT, GPIO_PUPD_NONE, FAN_PWM_PIN);
|
||||||
|
@ -71,5 +71,5 @@ void fan_ctrl_pwm_disable(void)
|
||||||
void fan_ctrl_pwm_set_duty(uint8_t percent)
|
void fan_ctrl_pwm_set_duty(uint8_t percent)
|
||||||
{
|
{
|
||||||
// as the timer has 100 steps per cycle, we can directly use the percentage value
|
// as the timer has 100 steps per cycle, we can directly use the percentage value
|
||||||
timer_set_oc_value(TIM21, TIM_OC1, percent);
|
timer_set_oc_value(TIM2, TIM_OC2, percent);
|
||||||
}
|
}
|
||||||
|
|
13
src/main.c
13
src/main.c
|
@ -1,4 +1,5 @@
|
||||||
#include <libopencm3/stm32/rcc.h>
|
#include <libopencm3/stm32/rcc.h>
|
||||||
|
#include <libopencm3/stm32/gpio.h>
|
||||||
#include <libopencm3/cm3/systick.h>
|
#include <libopencm3/cm3/systick.h>
|
||||||
#include <libopencmsis/core_cm3.h>
|
#include <libopencmsis/core_cm3.h>
|
||||||
|
|
||||||
|
@ -9,6 +10,8 @@
|
||||||
#include "fan_controller.h"
|
#include "fan_controller.h"
|
||||||
#include "eeprom_config.h"
|
#include "eeprom_config.h"
|
||||||
|
|
||||||
|
#include "pinout.h"
|
||||||
|
|
||||||
#define SYSTICK_FREQ 10 // Hz
|
#define SYSTICK_FREQ 10 // Hz
|
||||||
|
|
||||||
static uint64_t timebase_ms = 0;
|
static uint64_t timebase_ms = 0;
|
||||||
|
@ -66,7 +69,9 @@ int main(void)
|
||||||
uart_enqueue("TinyFanControl v" VERSION " initialized.\n");
|
uart_enqueue("TinyFanControl v" VERSION " initialized.\n");
|
||||||
|
|
||||||
uint8_t last_duty = 0;
|
uint8_t last_duty = 0;
|
||||||
bool use_dcdc = EEPROM_CONFIG_FLAGS & EEPROM_CONFIG_FLAG_USE_DCDC_CONTROL;
|
|
||||||
|
gpio_clear(LED_PORT, LED_PIN);
|
||||||
|
gpio_mode_setup(LED_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, LED_PIN);
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
if(systick_triggered) {
|
if(systick_triggered) {
|
||||||
|
@ -74,6 +79,8 @@ int main(void)
|
||||||
|
|
||||||
timebase_ms += 1000 / SYSTICK_FREQ;
|
timebase_ms += 1000 / SYSTICK_FREQ;
|
||||||
|
|
||||||
|
//uint32_t timebase_ms_fast = timebase_ms & 0xFFFFFFFF;
|
||||||
|
|
||||||
// start the measurement in the background.
|
// start the measurement in the background.
|
||||||
temp_sensor_trigger_update();
|
temp_sensor_trigger_update();
|
||||||
}
|
}
|
||||||
|
@ -87,12 +94,16 @@ int main(void)
|
||||||
|
|
||||||
// handle fan power-on and power-off
|
// handle fan power-on and power-off
|
||||||
if(last_duty == 0 && duty != 0) {
|
if(last_duty == 0 && duty != 0) {
|
||||||
|
gpio_set(LED_PORT, LED_PIN);
|
||||||
|
|
||||||
if(use_dcdc) {
|
if(use_dcdc) {
|
||||||
fan_ctrl_dc_enable();
|
fan_ctrl_dc_enable();
|
||||||
} else {
|
} else {
|
||||||
fan_ctrl_pwm_enable();
|
fan_ctrl_pwm_enable();
|
||||||
}
|
}
|
||||||
} else if(last_duty != 0 && duty == 0) {
|
} else if(last_duty != 0 && duty == 0) {
|
||||||
|
gpio_clear(LED_PORT, LED_PIN);
|
||||||
|
|
||||||
if(use_dcdc) {
|
if(use_dcdc) {
|
||||||
fan_ctrl_dc_disable();
|
fan_ctrl_dc_disable();
|
||||||
} else {
|
} else {
|
||||||
|
|
16
src/pinout.h
16
src/pinout.h
|
@ -3,10 +3,10 @@
|
||||||
|
|
||||||
/* Fan-related pins */
|
/* Fan-related pins */
|
||||||
|
|
||||||
#define FAN_PORT GPIOA
|
#define FAN_PORT GPIOB
|
||||||
|
|
||||||
#define FAN_PWM_PIN GPIO2
|
#define FAN_PWM_PIN GPIO3
|
||||||
#define FAN_TACHO_PIN GPIO3
|
//#define FAN_TACHO_PIN GPIO3
|
||||||
|
|
||||||
/* DC/DC control pins */
|
/* DC/DC control pins */
|
||||||
|
|
||||||
|
@ -29,8 +29,14 @@
|
||||||
|
|
||||||
#define UART_PORT GPIOA
|
#define UART_PORT GPIOA
|
||||||
|
|
||||||
#define UART_TX_PIN GPIO14
|
#define UART_TX_PIN GPIO2
|
||||||
#define UART_RX_PIN GPIO15
|
#define UART_RX_PIN GPIO3
|
||||||
|
|
||||||
|
/* LED */
|
||||||
|
|
||||||
|
#define LED_PORT GPIOA
|
||||||
|
|
||||||
|
#define LED_PIN GPIO10
|
||||||
|
|
||||||
|
|
||||||
#endif // PINOUT_H
|
#endif // PINOUT_H
|
||||||
|
|
Loading…
Reference in a new issue