Commit f61b2314 authored by Martin Vítek's avatar Martin Vítek
Browse files

Getting encoder pulses at lower resolution -> mutch better

parent 12470721
...@@ -32,3 +32,4 @@ Debug/* ...@@ -32,3 +32,4 @@ Debug/*
/Debug/ /Debug/
SW/.idea/ SW/.idea/
SW/build/ SW/build/
SW/cmake-build-debug/
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include <avr/interrupt.h> #include <avr/interrupt.h>
#include <stdint.h> #include <stdint.h>
#include <util/delay.h> #include <util/delay.h>
#include <stdio.h>
//Global instance //Global instance
...@@ -74,11 +75,16 @@ void SafeSolderingStation::init() ...@@ -74,11 +75,16 @@ void SafeSolderingStation::init()
backlight.set_intensity(100); backlight.set_intensity(100);
} }
char buffer[300];
void SafeSolderingStation::test_encoder() void SafeSolderingStation::test_encoder()
{ {
/*
if (enc.event) if (enc.event)
{ {
uint8_t n = sprintf(buffer, "Count: %d\n\r", enc.count);
uart.send_string(buffer);
/*
lcd.clear(); lcd.clear();
lcd.gotoxy_new(0,0); lcd.gotoxy_new(0,0);
...@@ -88,10 +94,10 @@ void SafeSolderingStation::test_encoder() ...@@ -88,10 +94,10 @@ void SafeSolderingStation::test_encoder()
if(enc.get_button()) lcd.write_text("Pressed"); if(enc.get_button()) lcd.write_text("Pressed");
else lcd.write_text("Released"); else lcd.write_text("Released");
*/
enc.event = false; enc.event = false;
} }
*/
} }
void SafeSolderingStation::test_backlight() void SafeSolderingStation::test_backlight()
......
...@@ -38,18 +38,18 @@ class encoder ...@@ -38,18 +38,18 @@ class encoder
PORTA.DIRCLR = PIN2_bm; PORTA.DIRCLR = PIN2_bm;
PORTB.DIRCLR = PIN2_bm | PIN3_bm; PORTB.DIRCLR = PIN2_bm | PIN3_bm;
//Pull-Up, IRQ on both edges, inverted readout //Pull-Up, ENC_A IRQ on falling edge, inverted readout
PORTA.PIN2CTRL = PORT_ISC_BOTHEDGES_gc | PORT_OPC_PULLUP_gc | PORT_INVEN_bm; PORTA.PIN2CTRL = PORT_ISC_BOTHEDGES_gc | PORT_OPC_PULLUP_gc | PORT_INVEN_bm;
PORTCFG.MPCMASK = PIN2_bm | PIN3_bm; PORTB.PIN2CTRL = PORT_ISC_FALLING_gc | PORT_OPC_PULLUP_gc | PORT_INVEN_bm;
PORTB.PIN2CTRL = PORT_ISC_BOTHEDGES_gc | PORT_OPC_PULLUP_gc | PORT_INVEN_bm; PORTB.PIN3CTRL = PORT_OPC_PULLUP_gc | PORT_INVEN_bm;
//Enable IRQs at low priority //Enable IRQ for button at low priority
PORTA.INTCTRL = PORT_INT0LVL_LO_gc; PORTA.INTCTRL = PORT_INT0LVL_LO_gc;
PORTA.INT0MASK = PIN2_bm; PORTA.INT0MASK = PIN2_bm;
PORTB.INTCTRL = PORT_INT0LVL_LO_gc | PORT_INT1LVL_LO_gc;
PORTB.INT0MASK = PIN2_bm;
PORTB.INT1MASK = PIN3_bm;
//Enable IRQ for ENC_A at low priority
PORTB.INTCTRL = PORT_INT0LVL_LO_gc;
PORTB.INT0MASK = PIN2_bm;
} }
bool get_button() { return button; } bool get_button() { return button; }
...@@ -88,6 +88,16 @@ class encoder ...@@ -88,6 +88,16 @@ class encoder
event = true; event = true;
} }
void simple_handler()
{
//Clockwise
if (PORTB.IN & PIN3_bm) count++;
//Counter-clockwise
else count--;
event = true;
}
void button_handler() void button_handler()
{ {
if (PORTA.IN & PIN2_bm) button = true; if (PORTA.IN & PIN2_bm) button = true;
......
...@@ -20,13 +20,15 @@ ISR(PORTA_INT0_vect) ...@@ -20,13 +20,15 @@ ISR(PORTA_INT0_vect)
//Encoder A //Encoder A
ISR(PORTB_INT0_vect) ISR(PORTB_INT0_vect)
{ {
sss.enc.A_handler(); //sss.enc.A_handler();
sss.enc.simple_handler();
} }
//Encoder B //Encoder B
ISR(PORTB_INT1_vect) ISR(PORTB_INT1_vect)
{ {
sss.enc.B_handler(); //Not used
//sss.enc.B_handler();
} }
//ADC //ADC
......
...@@ -43,9 +43,11 @@ int main() ...@@ -43,9 +43,11 @@ int main()
for(;;) for(;;)
{ {
sss.render.rendering_handler(); //sss.render.rendering_handler();
sss.render.update_temperatures(); //sss.render.update_temperatures();
_delay_ms(500); //_delay_ms(500);
sss.test_encoder();
} }
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment