Compare commits
3 Commits
7ade829a70
...
a35f66f2cd
Author | SHA1 | Date | |
---|---|---|---|
a35f66f2cd | |||
6fa071e1d1 | |||
47daf495bd |
@ -45,6 +45,8 @@ CFILES += calibration.c
|
|||||||
|
|
||||||
CFILES += temp-converter.c
|
CFILES += temp-converter.c
|
||||||
|
|
||||||
|
CFILES += rotary-encoder.c
|
||||||
|
|
||||||
DEFINES += -DDEBUGBUILD
|
DEFINES += -DDEBUGBUILD
|
||||||
#TODO
|
#TODO
|
||||||
|
|
||||||
|
42
stm-firmware/include/reflow-controller/rotary-encoder.h
Normal file
42
stm-firmware/include/reflow-controller/rotary-encoder.h
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
/* Reflow Oven Controller
|
||||||
|
*
|
||||||
|
* Copyright (C) 2020 Mario Hüttel <mario.huettel@gmx.net>
|
||||||
|
*
|
||||||
|
* This file is part of the Reflow Oven Controller Project.
|
||||||
|
*
|
||||||
|
* The reflow oven controller is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License version 2 as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* GDSII-Converter is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with the reflow oven controller project.
|
||||||
|
* If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __ROTARY_ENCODER_H__
|
||||||
|
#define __ROTARY_ENCODER_H__
|
||||||
|
|
||||||
|
#include <stm32/stm32f4xx.h>
|
||||||
|
|
||||||
|
#define ROTARY_ENCODER_TIMER TIM5
|
||||||
|
#define ROTARY_ENCODER_TIMER_RCC_MASK RCC_APB1ENR_TIM5EN
|
||||||
|
#define ROTARY_ENCODER_PIN1 0
|
||||||
|
#define ROTARY_ENCODER_PIN2 1
|
||||||
|
#define ROTARY_ENCODER_PORT GPIOA
|
||||||
|
#define ROTARY_ENCODER_PORT_ALTFUNC 2
|
||||||
|
#define ROTARY_ENCODER_RCC_MASK RCC_AHB1ENR_GPIOAEN
|
||||||
|
|
||||||
|
void rotary_encoder_setup(void);
|
||||||
|
|
||||||
|
uint32_t rotary_encoder_get_abs_val(void);
|
||||||
|
|
||||||
|
int32_t rotary_encoder_get_chage_val(void);
|
||||||
|
|
||||||
|
void rotary_encoder_stop(void);
|
||||||
|
|
||||||
|
#endif /* __ROTARY_ENCODER_H__ */
|
@ -28,6 +28,7 @@
|
|||||||
#include <reflow-controller/adc-meas.h>
|
#include <reflow-controller/adc-meas.h>
|
||||||
#include <reflow-controller/shell.h>
|
#include <reflow-controller/shell.h>
|
||||||
#include <reflow-controller/digio.h>
|
#include <reflow-controller/digio.h>
|
||||||
|
#include <reflow-controller/rotary-encoder.h>
|
||||||
#include <stm-periph/stm32-gpio-macros.h>
|
#include <stm-periph/stm32-gpio-macros.h>
|
||||||
#include <stm-periph/clock-enable-manager.h>
|
#include <stm-periph/clock-enable-manager.h>
|
||||||
#include <stm-periph/uart.h>
|
#include <stm-periph/uart.h>
|
||||||
@ -45,6 +46,8 @@ static void setup_nvic_priorities()
|
|||||||
|
|
||||||
static float pt1000_value;
|
static float pt1000_value;
|
||||||
static volatile int pt1000_value_status;
|
static volatile int pt1000_value_status;
|
||||||
|
static uint32_t rot;
|
||||||
|
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
@ -61,17 +64,15 @@ int main()
|
|||||||
digio_setup_default_all();
|
digio_setup_default_all();
|
||||||
led_setup();
|
led_setup();
|
||||||
loudspeaker_setup();
|
loudspeaker_setup();
|
||||||
|
rotary_encoder_setup();
|
||||||
|
|
||||||
uart_init_with_dma();
|
uart_init_with_dma();
|
||||||
|
|
||||||
shell_handle = shell_init();
|
shell_handle = shell_init();
|
||||||
|
|
||||||
/* Try random calibration */
|
|
||||||
adc_pt1000_set_resistance_calibration(-0.8f, 0.0f, true);
|
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
pt1000_value_status = adc_pt1000_get_current_resistance(&pt1000_value);
|
pt1000_value_status = adc_pt1000_get_current_resistance(&pt1000_value);
|
||||||
|
rot = rotary_encoder_get_abs_val();
|
||||||
uart_receive_status = uart_receive_data_with_dma(&uart_input, &uart_input_len);
|
uart_receive_status = uart_receive_data_with_dma(&uart_input, &uart_input_len);
|
||||||
if (uart_receive_status >= 1)
|
if (uart_receive_status >= 1)
|
||||||
shell_handle_input(shell_handle, uart_input, uart_input_len);
|
shell_handle_input(shell_handle, uart_input, uart_input_len);
|
||||||
|
78
stm-firmware/rotary-encoder.c
Normal file
78
stm-firmware/rotary-encoder.c
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
/* Reflow Oven Controller
|
||||||
|
*
|
||||||
|
* Copyright (C) 2020 Mario Hüttel <mario.huettel@gmx.net>
|
||||||
|
*
|
||||||
|
* This file is part of the Reflow Oven Controller Project.
|
||||||
|
*
|
||||||
|
* The reflow oven controller is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License version 2 as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* GDSII-Converter is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with the reflow oven controller project.
|
||||||
|
* If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <reflow-controller/rotary-encoder.h>
|
||||||
|
#include <stm-periph/clock-enable-manager.h>
|
||||||
|
#include <stm-periph/stm32-gpio-macros.h>
|
||||||
|
|
||||||
|
static inline void rotary_encoder_setup_pins(void)
|
||||||
|
{
|
||||||
|
rcc_manager_enable_clock(&RCC->AHB1ENR, BITMASK_TO_BITNO(ROTARY_ENCODER_RCC_MASK));
|
||||||
|
ROTARY_ENCODER_PORT->MODER &= MODER_DELETE(ROTARY_ENCODER_PIN1) & MODER_DELETE(ROTARY_ENCODER_PIN2);
|
||||||
|
ROTARY_ENCODER_PORT->MODER |= ALTFUNC(ROTARY_ENCODER_PIN1) | ALTFUNC(ROTARY_ENCODER_PIN2);
|
||||||
|
SETAF(ROTARY_ENCODER_PORT, ROTARY_ENCODER_PIN1, ROTARY_ENCODER_PORT_ALTFUNC);
|
||||||
|
SETAF(ROTARY_ENCODER_PORT, ROTARY_ENCODER_PIN2, ROTARY_ENCODER_PORT_ALTFUNC);
|
||||||
|
}
|
||||||
|
|
||||||
|
void rotary_encoder_setup(void)
|
||||||
|
{
|
||||||
|
rcc_manager_enable_clock(&RCC->APB1ENR, BITMASK_TO_BITNO(ROTARY_ENCODER_TIMER_RCC_MASK));
|
||||||
|
rotary_encoder_setup_pins();
|
||||||
|
|
||||||
|
ROTARY_ENCODER_TIMER->ARR = 0xFFFF;
|
||||||
|
ROTARY_ENCODER_TIMER->CNT = 0;
|
||||||
|
ROTARY_ENCODER_TIMER->CR2 = 0;
|
||||||
|
ROTARY_ENCODER_TIMER->SMCR = TIM_SMCR_SMS_0 | TIM_SMCR_SMS_1;
|
||||||
|
ROTARY_ENCODER_TIMER->CCMR1 = TIM_CCMR1_CC1S_0 | TIM_CCMR1_CC2S_0;
|
||||||
|
ROTARY_ENCODER_TIMER->CCER = TIM_CCER_CC1P | TIM_CCER_CC2P;
|
||||||
|
ROTARY_ENCODER_TIMER->PSC = 0;
|
||||||
|
ROTARY_ENCODER_TIMER->CR1 = TIM_CR1_CEN;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t rotary_encoder_get_abs_val(void)
|
||||||
|
{
|
||||||
|
return (uint32_t)ROTARY_ENCODER_TIMER->CNT;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t rotary_encoder_get_chage_val(void)
|
||||||
|
{
|
||||||
|
static uint32_t last_val = 0;
|
||||||
|
uint32_t val;
|
||||||
|
int32_t diff;
|
||||||
|
|
||||||
|
val = rotary_encoder_get_abs_val();
|
||||||
|
|
||||||
|
diff = val - last_val;
|
||||||
|
|
||||||
|
if (diff > 0xEFFF) {
|
||||||
|
diff = 0xFFFF - diff;
|
||||||
|
}
|
||||||
|
|
||||||
|
return diff;
|
||||||
|
}
|
||||||
|
|
||||||
|
void rotary_encoder_stop(void)
|
||||||
|
{
|
||||||
|
ROTARY_ENCODER_TIMER->CR1 = 0;
|
||||||
|
ROTARY_ENCODER_TIMER->CR2 = 0;
|
||||||
|
ROTARY_ENCODER_TIMER->ARR = 0;
|
||||||
|
rcc_manager_disable_clock(&RCC->APB1ENR, BITMASK_TO_BITNO(ROTARY_ENCODER_TIMER_RCC_MASK));
|
||||||
|
rcc_manager_disable_clock(&RCC->AHB1ENR, BITMASK_TO_BITNO(ROTARY_ENCODER_RCC_MASK));
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user