Ein Roboter mit bürstenlosem Antrieb, differenzial und NRF24L01 Funk. Großflächig gebaut um ein großes Solarpanel aufzunehmen. https://gitlab.informatik.hs-fulda.de/fdai5253/roboter
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.1 KiB

  1. #include "L298N.h"
  2. L298N::L298N() {
  3. DDR_A |= PIN_A;
  4. PORT_A &= ~PIN_A;
  5. DDR_B |= PIN_B;
  6. PORT_B &= ~PIN_B;
  7. DDRB |= 6; //set OC1A and OC1B as output
  8. PORTB &= ~6; //clear OC1A and OC1B
  9. //
  10. TCCR1A = 0; // set TCCRXA register to 0
  11. TCCR1B = 0; // set TCCRXB register to 0
  12. TCNT1 = 0; // reset counter value
  13. //OC1B behaviour
  14. TCCR1A |= (1 << COM1B1);
  15. //OCC1A behaviour
  16. TCCR1A |= (1 << COM1A1);
  17. TCCR1A |= (1 << WGM10);
  18. // 1:1, 62.5kHz
  19. TCCR1B |= (1 << CS10);
  20. TCCR1B |= (1 << WGM12);
  21. //enable timer
  22. TIMSK1 = 0; //no Interrupts
  23. }
  24. L298N::setPWM_A(int16_t pwmA) {
  25. if(pwmA < 0) {
  26. PWMA = 0xFF + pwmA;
  27. PORT_A |= PIN_A;
  28. } else {
  29. if(pwmA == 0) {
  30. PWMA = 0;
  31. PORT_A &= ~PIN_A;
  32. } else {
  33. PWMA = pwmA;
  34. PORT_A &= ~PIN_A;
  35. }
  36. }
  37. }
  38. L298N::setPWM_B(int16_t pwmB) {
  39. if(pwmB < 0) {
  40. PWMB = 0xFF + pwmB;
  41. PORT_B |= PIN_B;
  42. } else {
  43. if(pwmB == 0) {
  44. PWMB = 0;
  45. PORT_B &= ~PIN_B;
  46. } else {
  47. PWMB = pwmB;
  48. PORT_B &= ~PIN_B;
  49. }
  50. }
  51. }