diff --git a/.~lock.ideen_mechanik_und_elektronik.odt# b/.~lock.ideen_mechanik_und_elektronik.odt# index 1bf393e..affc95a 100644 --- a/.~lock.ideen_mechanik_und_elektronik.odt# +++ b/.~lock.ideen_mechanik_und_elektronik.odt# @@ -1 +1 @@ -,yves,yves-UB,03.02.2020 23:03,file:///home/yves/.config/libreoffice/4; \ No newline at end of file +,yves,yves-UB,05.02.2020 13:15,file:///home/yves/.config/libreoffice/4; \ No newline at end of file diff --git a/Code/libraries/L298N/L298N.cpp b/Code/libraries/L298N/L298N.cpp new file mode 100644 index 0000000..fbe6818 --- /dev/null +++ b/Code/libraries/L298N/L298N.cpp @@ -0,0 +1,57 @@ +#include "L298N.h" + + L298N::L298N() { + DDR_A |= PIN_A; + PORT_A &= ~PIN_A; + DDR_B |= PIN_B; + PORT_B &= ~PIN_B; + + DDRB |= 6; //set OC1A and OC1B as output + PORTB &= ~6; //clear OC1A and OC1B + + // + TCCR1A = 0; // set TCCRXA register to 0 + TCCR1B = 0; // set TCCRXB register to 0 + TCNT1 = 0; // reset counter value + + //OC1B behaviour + TCCR1A |= (1 << COM1B1); + //OCC1A behaviour + TCCR1A |= (1 << COM1A1); + TCCR1A |= (1 << WGM10); + + // 1:1, 62.5kHz + TCCR1B |= (1 << CS10); + + TCCR1B |= (1 << WGM12); + //enable timer + TIMSK1 = 0; //no Interrupts + } + L298N::setPWM_A(int16_t pwmA) { + if(pwmA < 0) { + PWMA = 0xFF + pwmA; + PORT_A |= PIN_A; + } else { + if(pwmA == 0) { + PWMA = 0; + PORT_A &= ~PIN_A; + } else { + PWMA = pwmA; + PORT_A &= ~PIN_A; + } + } + } + L298N::setPWM_B(int16_t pwmB) { + if(pwmB < 0) { + PWMB = 0xFF + pwmB; + PORT_B |= PIN_B; + } else { + if(pwmB == 0) { + PWMB = 0; + PORT_B &= ~PIN_B; + } else { + PWMB = pwmB; + PORT_B &= ~PIN_B; + } + } + } diff --git a/Code/libraries/L298N/L298N.h b/Code/libraries/L298N/L298N.h new file mode 100644 index 0000000..883f66c --- /dev/null +++ b/Code/libraries/L298N/L298N.h @@ -0,0 +1,28 @@ +#pragma once + +#ifndef L298N_h +#define L298N_h + +#include + +#define PIN_A 0x01 +#define PORT_A PORTB +#define DDR_A DDRB +#define PIN_B 128 +#define PORT_B PORTD +#define DDR_B DDRD + +#define PWMA OCR1B +#define PWMB OCR1A + +class L298N { + public: + L298N(); + setPWM_A(int16_t pwmA); + setPWM_B(int16_t pwmB); + + //private: + +}; + +#endif diff --git a/Code/libraries/L298N/keywords.txt b/Code/libraries/L298N/keywords.txt new file mode 100644 index 0000000..33bae47 --- /dev/null +++ b/Code/libraries/L298N/keywords.txt @@ -0,0 +1,22 @@ +######################################### +# Syntax Coloring Map For L298N Library +######################################### + +####################################### +# Datatypes (KEYWORD1) +####################################### + +L298N KEYWORD1 + + +####################################### +# Methods and Functions (KEYWORD2) +####################################### + +setPWMA KEYWORD2 +setPWMB KEYWORD2 + + +####################################### +# Constants (LITERAL1) +####################################### diff --git a/Code/miniRobot/miniRobot.ino b/Code/miniRobot/miniRobot.ino index c05a9f1..bcb2398 100644 --- a/Code/miniRobot/miniRobot.ino +++ b/Code/miniRobot/miniRobot.ino @@ -37,14 +37,14 @@ const byte address[6] = "00001"; #include #define BEEP 14 - +/* #define PWM_PINA 10 #define PINA 8 #define PWM_PINB 9 #define PINB 7 #define NUMPWM 1 -#define RESOLUTION 255 +#define RESOLUTION 255 */ //MX1508 motorA(PWM_PINA,PINA, FAST_DECAY, NUMPWM); //MX1508 motorB(PWM_PINB,PINB, FAST_DECAY, NUMPWM); diff --git a/ideen_mechanik_und_elektronik.odt b/ideen_mechanik_und_elektronik.odt index 8970564..dd56f82 100644 Binary files a/ideen_mechanik_und_elektronik.odt and b/ideen_mechanik_und_elektronik.odt differ