Show motor speed on LED display 2
This commit is contained in:
parent
e86efa6e6a
commit
1c893002a9
3 changed files with 23 additions and 2 deletions
|
|
@ -7,4 +7,10 @@
|
||||||
void motor_init(void);
|
void motor_init(void);
|
||||||
void motor_set_speed(int speed_rpm);
|
void motor_set_speed(int speed_rpm);
|
||||||
|
|
||||||
|
struct motor_state {
|
||||||
|
int speed_rpm;
|
||||||
|
};
|
||||||
|
|
||||||
|
extern struct motor_state st_motor;
|
||||||
|
|
||||||
#endif /* __MOTOR_H__ */
|
#endif /* __MOTOR_H__ */
|
||||||
|
|
|
||||||
14
src/motor.c
14
src/motor.c
|
|
@ -2,7 +2,12 @@
|
||||||
#include <motor.h>
|
#include <motor.h>
|
||||||
|
|
||||||
|
|
||||||
|
struct motor_state st_motor;
|
||||||
|
|
||||||
|
|
||||||
void motor_init() {
|
void motor_init() {
|
||||||
|
memset(&st_motor, 0, sizeof(st_motor));
|
||||||
|
|
||||||
/* PB1 (BT1) -> Open drain, TIM2 CH3N for speed PWM*/
|
/* PB1 (BT1) -> Open drain, TIM2 CH3N for speed PWM*/
|
||||||
GPIOB->MODER &= ~GPIO_MODER_MODER0_Msk;
|
GPIOB->MODER &= ~GPIO_MODER_MODER0_Msk;
|
||||||
GPIOB->MODER |= AF(1);
|
GPIOB->MODER |= AF(1);
|
||||||
|
|
@ -30,9 +35,18 @@ void motor_init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void motor_set_speed(int speed_rpm) {
|
void motor_set_speed(int speed_rpm) {
|
||||||
|
if (speed_rpm > 3000) {
|
||||||
|
speed_rpm = 3000;
|
||||||
|
} else if (speed_rpm < -3000) {
|
||||||
|
speed_rpm = -3000;
|
||||||
|
}
|
||||||
|
|
||||||
|
st_motor.speed_rpm = speed_rpm;
|
||||||
|
|
||||||
int speed = speed_rpm * 65535 / 3000;
|
int speed = speed_rpm * 65535 / 3000;
|
||||||
if (speed == 0) {
|
if (speed == 0) {
|
||||||
GPIOB->BRR = 1<<12;
|
GPIOB->BRR = 1<<12;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
GPIOB->BSRR = 1<<12;
|
GPIOB->BSRR = 1<<12;
|
||||||
if (speed < 0) {
|
if (speed < 0) {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
|
|
||||||
#include <proto.h>
|
#include <proto.h>
|
||||||
#include <adc.h>
|
#include <adc.h>
|
||||||
|
#include <motor.h>
|
||||||
#include <lcd.h>
|
#include <lcd.h>
|
||||||
#include <led7seg.h>
|
#include <led7seg.h>
|
||||||
|
|
||||||
|
|
@ -291,12 +292,12 @@ ErrorCode tx_update_display() {
|
||||||
},
|
},
|
||||||
.led = {
|
.led = {
|
||||||
sys_time_us/10000,
|
sys_time_us/10000,
|
||||||
0,
|
st_motor.speed_rpm,
|
||||||
0
|
0
|
||||||
},
|
},
|
||||||
.led_fmt = {
|
.led_fmt = {
|
||||||
PROTO_LED_FMT_DEC | PROTO_LED_FMT_DP_2,
|
PROTO_LED_FMT_DEC | PROTO_LED_FMT_DP_2,
|
||||||
PROTO_LED_FMT_OFF,
|
PROTO_LED_FMT_DEC,
|
||||||
PROTO_LED_FMT_OFF,
|
PROTO_LED_FMT_OFF,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue