Browse Source

Motortreiber Lib added

master
Yves Ehrlich 5 years ago
parent
commit
2542f17c3a
  1. 2
      .~lock.ideen_mechanik_und_elektronik.odt#
  2. 57
      Code/libraries/L298N/L298N.cpp
  3. 28
      Code/libraries/L298N/L298N.h
  4. 22
      Code/libraries/L298N/keywords.txt
  5. 4
      Code/miniRobot/miniRobot.ino
  6. BIN
      ideen_mechanik_und_elektronik.odt

2
.~lock.ideen_mechanik_und_elektronik.odt#

@ -1 +1 @@
,yves,yves-UB,03.02.2020 23:03,file:///home/yves/.config/libreoffice/4;
,yves,yves-UB,05.02.2020 13:15,file:///home/yves/.config/libreoffice/4;

57
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;
}
}
}

28
Code/libraries/L298N/L298N.h

@ -0,0 +1,28 @@
#pragma once
#ifndef L298N_h
#define L298N_h
#include <Arduino.h>
#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

22
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)
#######################################

4
Code/miniRobot/miniRobot.ino

@ -37,14 +37,14 @@ const byte address[6] = "00001";
#include <L298N.h> #include <L298N.h>
#define BEEP 14 #define BEEP 14
/*
#define PWM_PINA 10 #define PWM_PINA 10
#define PINA 8 #define PINA 8
#define PWM_PINB 9 #define PWM_PINB 9
#define PINB 7 #define PINB 7
#define NUMPWM 1 #define NUMPWM 1
#define RESOLUTION 255
#define RESOLUTION 255 */
//MX1508 motorA(PWM_PINA,PINA, FAST_DECAY, NUMPWM); //MX1508 motorA(PWM_PINA,PINA, FAST_DECAY, NUMPWM);
//MX1508 motorB(PWM_PINB,PINB, FAST_DECAY, NUMPWM); //MX1508 motorB(PWM_PINB,PINB, FAST_DECAY, NUMPWM);

BIN
ideen_mechanik_und_elektronik.odt

Loading…
Cancel
Save