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/*
/Debug/
SW/.idea/
SW/build/
SW/cmake-build-debug/
......@@ -5,6 +5,7 @@
#include <avr/interrupt.h>
#include <stdint.h>
#include <util/delay.h>
#include <stdio.h>
//Global instance
......@@ -74,11 +75,16 @@ void SafeSolderingStation::init()
backlight.set_intensity(100);
}
char buffer[300];
void SafeSolderingStation::test_encoder()
{
/*
if (enc.event)
{
uint8_t n = sprintf(buffer, "Count: %d\n\r", enc.count);
uart.send_string(buffer);
/*
lcd.clear();
lcd.gotoxy_new(0,0);
......@@ -88,10 +94,10 @@ void SafeSolderingStation::test_encoder()
if(enc.get_button()) lcd.write_text("Pressed");
else lcd.write_text("Released");
*/
enc.event = false;
}
*/
}
void SafeSolderingStation::test_backlight()
......
......@@ -38,18 +38,18 @@ class encoder
PORTA.DIRCLR = PIN2_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;
PORTCFG.MPCMASK = PIN2_bm | PIN3_bm;
PORTB.PIN2CTRL = PORT_ISC_BOTHEDGES_gc | PORT_OPC_PULLUP_gc | PORT_INVEN_bm;
PORTB.PIN2CTRL = PORT_ISC_FALLING_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.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; }
......@@ -88,6 +88,16 @@ class encoder
event = true;
}
void simple_handler()
{
//Clockwise
if (PORTB.IN & PIN3_bm) count++;
//Counter-clockwise
else count--;
event = true;
}
void button_handler()
{
if (PORTA.IN & PIN2_bm) button = true;
......
......@@ -20,13 +20,15 @@ ISR(PORTA_INT0_vect)
//Encoder A
ISR(PORTB_INT0_vect)
{
sss.enc.A_handler();
//sss.enc.A_handler();
sss.enc.simple_handler();
}
//Encoder B
ISR(PORTB_INT1_vect)
{
sss.enc.B_handler();
//Not used
//sss.enc.B_handler();
}
//ADC
......
......@@ -43,9 +43,11 @@ int main()
for(;;)
{
sss.render.rendering_handler();
sss.render.update_temperatures();
_delay_ms(500);
//sss.render.rendering_handler();
//sss.render.update_temperatures();
//_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