Added untested pwm input
This commit is contained in:
parent
18aef38fb8
commit
cfc583a8cf
|
@ -3,8 +3,8 @@ F_CPU = 8000000
|
||||||
|
|
||||||
VERSION = 0.1
|
VERSION = 0.1
|
||||||
|
|
||||||
HEADERS = pwm.h
|
HEADERS = pwm.h input.h
|
||||||
SRC = main.c
|
SRC = main.c input.c
|
||||||
TARGET = mate-driver-$(AVRMCU)
|
TARGET = mate-driver-$(AVRMCU)
|
||||||
OBJDIR = bin
|
OBJDIR = bin
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
#include "input.h"
|
||||||
|
|
||||||
|
uint16_t volatile last_count;
|
||||||
|
|
||||||
|
void input_init() {
|
||||||
|
MCUCR |= (1 << ISC10);
|
||||||
|
EIFR |= (1 << INTF1);
|
||||||
|
|
||||||
|
last_count = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
ISR(INT1_vect) {
|
||||||
|
if((PORTB & (1 << PD3)) != 0) {
|
||||||
|
TCCR1B |= (1 << CS11); //Prescaler 8, enable Timer
|
||||||
|
TCNT1 = 0;
|
||||||
|
} else {
|
||||||
|
TCCR1B &= ~(1 << CS11); //Prescaler 8, disable Timer
|
||||||
|
last_count = TCNT1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t input_get_result() {
|
||||||
|
uint16_t tmp = last_count;
|
||||||
|
if(tmp < 1000) {
|
||||||
|
tmp = 0;
|
||||||
|
}
|
||||||
|
tmp = (tmp - 1000);
|
||||||
|
if(tmp > 1000) {
|
||||||
|
tmp = 1000;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ((int16_t)tmp) / 2 - 1000;
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
#ifndef _INPUT_H
|
||||||
|
#define _INPUT_H
|
||||||
|
|
||||||
|
#include <avr/io.h>
|
||||||
|
#include <avr/interrupt.h>
|
||||||
|
|
||||||
|
|
||||||
|
void input_init(void);
|
||||||
|
int16_t input_get_result(void);
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
|
@ -2,6 +2,7 @@
|
||||||
#include <util/delay.h>
|
#include <util/delay.h>
|
||||||
|
|
||||||
#include "pwm.h"
|
#include "pwm.h"
|
||||||
|
#include "input.h"
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
|
|
||||||
|
@ -9,6 +10,7 @@ int main(void) {
|
||||||
_delay_ms(5000);
|
_delay_ms(5000);
|
||||||
|
|
||||||
hbridge_init();
|
hbridge_init();
|
||||||
|
input_init();
|
||||||
|
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
|
|
Loading…
Reference in New Issue