mirror of
https://github.com/eddyem/stm32samples.git
synced 2026-03-21 01:00:56 +03:00
little fix
This commit is contained in:
@@ -46,7 +46,7 @@ SCRIPT_DIR = $(OPENCM3_DIR)/scripts
|
||||
|
||||
###############################################################################
|
||||
# C flags
|
||||
CFLAGS += -Os -g
|
||||
CFLAGS += -O3 -g
|
||||
CFLAGS += -Wall -Wextra -Wshadow -Wimplicit-function-declaration
|
||||
CFLAGS += -Wredundant-decls
|
||||
# -Wmissing-prototypes -Wstrict-prototypes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
Jeep crankshaft signals generator
|
||||
|
||||
Speed from 180 to 6000RPM
|
||||
Speed from 200 to 6000RPM
|
||||
Buttons "+" and "-", LEDS "MIN" and "MAX"
|
||||
|
||||
written for chinese devboard based on STM32F103RBT6
|
||||
|
||||
Binary file not shown.
@@ -43,7 +43,7 @@ int main(){
|
||||
while(1){
|
||||
usbd_poll(usbd_dev);
|
||||
if(usbdatalen){ // there's something in USB buffer
|
||||
usbdatalen = parce_incoming_buf(usbdatabuf, usbdatalen);
|
||||
usbdatalen = parse_incoming_buf(usbdatabuf, usbdatalen);
|
||||
}
|
||||
check_btns();
|
||||
if(Timer - Old_timer > 999){ // one-second cycle
|
||||
|
||||
@@ -23,9 +23,9 @@
|
||||
#include "user_proto.h" // for print_int
|
||||
|
||||
// current speed
|
||||
int32_t current_RPM = 0;
|
||||
uint16_t current_RPM = 0;
|
||||
void get_RPM();
|
||||
uint16_t get_ARR(int32_t RPM);
|
||||
uint16_t get_ARR(uint32_t RPM);
|
||||
|
||||
// pulses: 16 1/0, 4 1/1, 16 1/0, 4 0/0,
|
||||
const uint8_t pulses[] = {
|
||||
@@ -58,8 +58,8 @@ void tim2_isr(){
|
||||
GPIO_BSRR(OUTP_PORT) = OUTP_PIN;
|
||||
else
|
||||
GPIO_BSRR(OUTP_PORT) = OUTP_PIN << 16;
|
||||
TIM2_SR = 0;
|
||||
}
|
||||
TIM2_SR = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -67,14 +67,17 @@ void tim2_isr(){
|
||||
* RPM = 1/tim2_arr / 40 * 60
|
||||
*/
|
||||
void get_RPM(){
|
||||
current_RPM = 3000000 / (int32_t)TIM2_ARR;
|
||||
current_RPM /= 2;
|
||||
uint32_t R = 3000000 / (uint32_t)TIM2_ARR;
|
||||
current_RPM = R/2;
|
||||
//current_RPM = R;
|
||||
//current_RPM >>= 1; // x/2 != x>>1, WTF?
|
||||
}
|
||||
|
||||
// calculate TIM2_ARR by RPM
|
||||
uint16_t get_ARR(int32_t RPM){
|
||||
int32_t R = 3000000 / RPM;
|
||||
uint16_t get_ARR(uint32_t RPM){
|
||||
uint32_t R = 3000000 / RPM;
|
||||
R /= 2;
|
||||
//R >>= 1;
|
||||
return (uint16_t)R;
|
||||
}
|
||||
|
||||
|
||||
@@ -31,13 +31,13 @@
|
||||
//~ #define TM2_MAX_SPEED (250)
|
||||
// max & min rotation speed
|
||||
#define MAX_RPM (6000)
|
||||
#define MIN_RPM (180)
|
||||
#define MIN_RPM (200)
|
||||
|
||||
|
||||
void tim2_init();
|
||||
void increase_speed();
|
||||
void decrease_speed();
|
||||
|
||||
extern int32_t current_RPM;
|
||||
extern uint16_t current_RPM;
|
||||
|
||||
#endif // __TIMER_H__
|
||||
|
||||
@@ -34,13 +34,13 @@ void help(){
|
||||
}
|
||||
|
||||
/**
|
||||
* parce command buffer buf with length len
|
||||
* parse command buffer buf with length len
|
||||
* return 0 if buffer processed or len if there's not enough data in buffer
|
||||
*/
|
||||
int parce_incoming_buf(char *buf, int len){
|
||||
int parse_incoming_buf(char *buf, int len){
|
||||
uint8_t command;
|
||||
int i = 0;
|
||||
for(; i < len; i++){
|
||||
for(; i < len; ++i){
|
||||
command = buf[i];
|
||||
if(!command) continue; // omit zero
|
||||
switch (command){
|
||||
|
||||
@@ -42,6 +42,6 @@ void prnt(uint8_t *wrd);
|
||||
void print_int(int32_t N);
|
||||
void print_hex(uint8_t *buff, uint8_t l);
|
||||
|
||||
int parce_incoming_buf(char *buf, int len);
|
||||
int parse_incoming_buf(char *buf, int len);
|
||||
|
||||
#endif // __USER_PROTO_H__
|
||||
|
||||
Reference in New Issue
Block a user