Minor changes to cli, adc and rotary encoder

master
_N0x 2 years ago
parent 2e6026421e
commit a2203b7cd5

@ -281,6 +281,7 @@ static void cmd_led_on(const char* _data){
}
}
//================================================================================================================================
// Funktion: cmd_led_off
// Kann verwendet werden, um eine LED auszuschalten
@ -349,8 +350,6 @@ static void cmd_adc(const char* _data){
char lm35Data[50];
int loopInterval = 500;
int repeat = strcmp(_data, "R") == 0 ? 1 : 0; /* Check if repeat flag is set*/
do
{
if(Timer_getTick() - g_startMS >= loopInterval){
@ -372,14 +371,13 @@ static void cmd_adc(const char* _data){
print_string("----------");
print_string(NEXT_LINE);
}
} while (repeat); // repeat if repeat-flag is given
} while (strcmp(_data, "R") == 0 ? 1 : 0); /* Check if repeat flag is set*/
}
//================================================================================================================================
// Funktion: cmd_rotary
// Wird verwendet um die Daten von Poti und LM35 zu lesen
// Wird verwendet um die Bewegung von Dregeber zu lesen
// Parameter: _data: Zeichenkette mit Parametern des Befehls.
//
// Rückgabewert: keine

@ -7,42 +7,73 @@
#include "adc.h"
typedef struct ADC_t ADC_t;
struct ADC_t{
/* ADC Data */
uint16_t uiADC :16;
/* ADCSRA */
uint8_t uiADPS0 :1;
uint8_t uiADPS1 :1;
uint8_t uiADPS2 :1;
uint8_t uiADIE :1;
uint8_t uiADIF :1;
uint8_t uiADATE :1;
uint8_t uiADSC :1;
uint8_t uiADEN :1;
/* ADCSRB */
uint8_t uiADTS0 :1;
uint8_t uiADTS1 :1;
uint8_t uiADTS2 :1;
uint8_t nui2 :3;
uint8_t uiACME :1;
uint8_t nui1 :1;
/* ADMUX */
uint8_t uiMUX :5;
uint8_t uiADLAR :1;
uint8_t uiREFS0 :1;
uint8_t uiREFS1 :1;
};
#define myADC ((ADC_t*)(0x78))
void
adc_init(void)
{
ADMUX = (1<<REFS1)|
(0<<REFS0)| /* Set Voltage reference to 2.56V */
(0<<ADLAR) /* Set ADLAR to 0 to not left adjust the presentation of the conversion result */
;
myADC->uiADLAR = 0;
myADC->uiREFS0 = 0; /* Set ADLAR to 0 to not left adjust the presentation of the conversion result */
myADC->uiREFS1 = 0; /* Set Voltage reference to 2.56V */
ADCSRA = (1<<ADEN)| /* Enable ADC */
(0<<ADATE)| /* Disable the ADC auto trigger */
(1<<ADIE)| /* Enable the ADC interrupt */
(1<<ADPS2)|
(1<<ADPS1)|
(1<<ADPS0) /* Set ADC Prescaler to 128 */
;
myADC->uiADPS0 = 1; /* Set ADC Prescaler to 128 */
myADC->uiADPS1 = 1;
myADC->uiADPS2 = 1;
myADC->uiADIE = 1; /* Enable the ADC interrupt */
myADC->uiADATE = 0; /* Disable the ADC auto trigger */
myADC->uiADEN = 1; /* Enable ADC */
}
volatile int done = 1;
/* ADC 1 */
uint16_t
uint16_t
adc_get_poti(void)
{
uint16_t adc;
ADCSRA &= ~(1<<ADIE); /* Disable interrupt */
ADMUX |= (1<<MUX0); /* Set ADMUX to access ADC channel 1 */
ADCSRA |= (1<<ADSC); /* Start the conversion */
//myADC->uiADIE = 0; /* Disable interrupt */
myADC->uiMUX = 1; /* Set ADMUX to access ADC channel 1 */
myADC->uiADSC = 1; /* Start the conversion */
done = 0; /* reset the done flag to false */
while(done == 0); /* Wait till conversion completes */
adc = ADC;
adc = myADC->uiADC;
ADCSRA |= (1<<ADIE); /* Enable the interrupt again */
//myADC->uiADIE = 1; /* Enable the interrupt again */
return adc;
}
@ -53,18 +84,19 @@ uint16_t
adc_get_LM35(void)
{
uint16_t adc;
ADCSRA &= ~(1<<ADIE); /* Disable interrupt */
ADMUX &= (0<<MUX0); /* Set ADMUX to access ADC channel 0 */
ADCSRA |= (1<<ADSC); /* Start the conversion */
//myADC->uiADIE = 0; /* Disable interrupt */
myADC->uiMUX = 0; /* Set ADMUX to access ADC channel 1 */
myADC->uiADSC = 1; /* Start the conversion */
done = 0; /* reset the done flag to false */
while(done == 0); /* Wait till conversion completes */
adc = ADC;
adc = myADC->uiADC;
ADCSRA |= (1<<ADIE); /* Enable the interrupt again */
//myADC->uiADIE = 1; /* Enable the interrupt again */
return adc;
}

@ -13,9 +13,9 @@
/* enums */
enum{
S2, S3, S4, S5, S6, S7,
LEFT1, LEFT2, LEFT3, RIGHT1, RIGHT2, RIGHT3,
INIT, WAIT
} RotaryState = INIT; /* Emus for the stoplight task (task 3) */
} RotaryState = INIT; /* Enum for the rotary enc */
int16_t count;
@ -24,23 +24,12 @@ drehgeber_init(void)
{
DDRC &= ~(7<<DDC5); /* Set bit 5-7 of Data Direction Register C as input */
PORTC |= (7<<PORTC5); /* Initialize bit 5-7 of PORTC as for pull up resistor */
/* With Timer */
// TCCR2A |= (1<<WGM21);
// TCCR2B |= (3<<CS20);
// TIMSK2 |= (1<<OCIE2A);
// OCR2A = 250 - 1;
/* With external interrupt */
PCICR |= (1<<PCIE2);
PCMSK2 |= (1<<PCINT23)|(1<<PCINT22);
}
// ISR(TIMER2_COMPA_vect)
// {
// drehgeber_process();
// }
ISR(PCINT2_vect)
{
drehgeber_process();
@ -63,18 +52,18 @@ drehgeber_process(void)
case WAIT:
if(enc == 1)
{
RotaryState = S2;
RotaryState = LEFT1;
}
if(enc == 2)
{
RotaryState = S5;
RotaryState = RIGHT1;
}
break;
case S2:
case LEFT1:
if(enc == 3)
{
RotaryState = S3;
RotaryState = LEFT2;
}
if(enc == 0)
{
@ -82,18 +71,18 @@ drehgeber_process(void)
}
break;
case S3:
case LEFT2:
if(enc == 2)
{
RotaryState = S4;
RotaryState = LEFT3;
}
if(enc == 1)
{
RotaryState = S2;
RotaryState = LEFT1;
}
break;
case S4:
case LEFT3:
if(enc == 0)
{
count++;
@ -101,14 +90,14 @@ drehgeber_process(void)
}
if(enc == 3)
{
RotaryState = S3;
RotaryState = LEFT2;
}
break;
case S5:
case RIGHT1:
if(enc == 3)
{
RotaryState = S6;
RotaryState = RIGHT2;
}
if(enc == 0)
{
@ -116,19 +105,19 @@ drehgeber_process(void)
}
break;
case S6:
case RIGHT2:
if(enc == 1)
{
RotaryState = S7;
RotaryState = RIGHT3;
}
if(enc == 2)
{
RotaryState = S5;
RotaryState = RIGHT1;
}
break;
case S7:
case RIGHT3:
if(enc == 0)
{
count--;
@ -136,7 +125,7 @@ drehgeber_process(void)
}
if(enc == 3)
{
RotaryState = S6;
RotaryState = RIGHT2;
}
break;
}

Loading…
Cancel
Save