Compare commits

...

2 Commits

Author SHA1 Message Date
f48f18ac64 remove unneeded files 2019-12-01 20:56:28 +01:00
3dafc11535 interprete encoder quadrature signals correctly 2019-12-01 20:54:24 +01:00
11 changed files with 93 additions and 29 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

69
code/src/encoder.c Normal file
View File

@@ -0,0 +1,69 @@
#include <avr/io.h>
#include <avr/interrupt.h>
#define ENC_PORT PORTD
#define ENC_DDR DDRD
#define ENC_A PIND&(1<<2)
#define ENC_B PIND&(1<<4)
#define ENC_CCW 0
#define ENC_CW 1
void encoder_action(uint8_t dir);
volatile uint8_t encoder_direction;
ISR(INT0_vect)
{
if (ENC_B)
{
if (ENC_A)
{
encoder_direction = ENC_CCW;
encoder_action(0);
}
else
{
encoder_direction = ENC_CW;
}
}
else
{
if (ENC_A)
{
encoder_direction = ENC_CW;
}
else
{
encoder_direction = ENC_CCW;
encoder_action(0);
}
}
}
ISR (PCINT3_vect){
if (ENC_B)
{
if (ENC_A)
{
encoder_direction = ENC_CW;
encoder_action(1);
}
else
{
encoder_direction = ENC_CCW;
}
}
else
{
if (ENC_A)
{
encoder_direction = ENC_CCW;
}
else
{
encoder_direction = ENC_CW;
encoder_action(1);
}
}
}

View File

@@ -41,6 +41,20 @@ int8_t parse_nmea_gps(char input_string[RX_INPUT_BUFFER_SIZE], uint8_t output_bu
return -1;
}
void encoder_action(uint8_t dir){
if (dir) {
if(get_menu_active())
menu_up_down(1);
else
OCR2A++;
} else {
if(get_menu_active())
menu_up_down(-1);
else
OCR2A--;
}
}
int main(void){
setup();
printf("Moin\n\r");
@@ -134,14 +148,18 @@ void setup(){
//--------------------------
//External Interrupt Mask Register
EIMSK |= (1 << INT0) | //Aktiviere Interrupt INT0
(1 << INT1); //Aktiviere Interrupt INT1
EIMSK |= (1 << INT0) //Aktiviere Interrupt INT0
| (1 << INT1); //Aktiviere Interrupt INT1
//External Interrupt Control Register A
EICRA |= (0 << ISC10) | //Interrupt bei jedem Pegelwechsel auf INT1
(1 << ISC11) |
(1 << ISC00) | //Interrupt bei jedem Pegelwechsel auf INT0
(1 << ISC01);
EICRA |= (0 << ISC10) //Interrupt bei jedem Pegelwechsel auf INT1
| (1 << ISC11)
| (1 << ISC00) //Interrupt bei jedem Pegelwechsel auf INT0
| (0 << ISC01);
// PCINT for ENCODER_B
PCICR |= (1 << PCIE3);
PCMSK3 |= (1 << PCINT28);
//--------------------------
// Timer + Zeitinterrupts
@@ -168,24 +186,8 @@ void setup(){
}
//Encoder rotate
ISR(INT0_vect) {
if (PIND & ENCODER_B) {
if(get_menu_active())
menu_up_down(1);
else
OCR2A++;
} else {
if(get_menu_active())
menu_up_down(-1);
else
OCR2A--;
}
}
//Encoder Button
ISR(INT1_vect) {
printf("button\n\r");
enter_menu();
}

View File

@@ -10,13 +10,6 @@ int8_t menu_val_timezone;
uint8_t menu_val_format_ee EEMEM;
uint8_t menu_val_format;
//void debug_menu(){
// printf("state: %d\r\n", state);
// printf("selected: %d\r\n", selected);
// printf("timezone: %d\r\n", menu_val_timezone);
// printf("\r\n");
//}
uint8_t get_menu_active(){
if(state != OFF)
return 1;