Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/adafruit/Adafruit-Motor-Shield-library.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Schmalz <brian@schmalzhaus.com>2012-09-20 15:58:50 +0400
committerBrian Schmalz <brian@schmalzhaus.com>2012-09-20 15:58:50 +0400
commitc7189c22ea7a027dfcecd0fb89bae5189f5a9d69 (patch)
treec4431b9b0f257353f7e6d6f87898475bd6559797
parentdd30da7ecb40581377dc4bb8fc9044a995ddb4d4 (diff)
Starting work on adding PIC32/chipKIT/MPIDE support to AFMotor
It compiles now, but doesn't do much else.
-rw-r--r--AFMotor.cpp25
-rw-r--r--AFMotor.h46
2 files changed, 56 insertions, 15 deletions
diff --git a/AFMotor.cpp b/AFMotor.cpp
index 8ac0c08..220e066 100644
--- a/AFMotor.cpp
+++ b/AFMotor.cpp
@@ -4,11 +4,14 @@
#if (ARDUINO >= 100)
- #include "Arduino.h"
+ #include "Arduino.h"
#else
- #include <avr/io.h>
- #include "WProgram.h"
+ #if defined(__AVR__)
+ #include <avr/io.h>
+ #endif
+ #include "WProgram.h"
#endif
+
#include "AFMotor.h"
@@ -94,6 +97,8 @@ inline void initPWM1(uint8_t freq) {
TCCR1A |= _BV(COM1A1) | _BV(WGM10); // fast PWM, turn on oc1a
TCCR1B = (freq & 0x7) | _BV(WGM12);
OCR1A = 0;
+#elif defined(__PIC32MX__)
+/// TODO: Fill this in for PIC32
#else
#error "This chip is not supported!"
#endif
@@ -111,6 +116,8 @@ inline void setPWM1(uint8_t s) {
#elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
// on arduino mega, pin 11 is now PB5 (OC1A)
OCR1A = s;
+#elif defined(__PIC32MX__)
+/// TODO: Fill this in for PIC32
#else
#error "This chip is not supported!"
#endif
@@ -131,6 +138,8 @@ inline void initPWM2(uint8_t freq) {
TCCR3A |= _BV(COM1C1) | _BV(WGM10); // fast PWM, turn on oc3c
TCCR3B = (freq & 0x7) | _BV(WGM12);
OCR3C = 0;
+#elif defined(__PIC32MX__)
+/// TODO: Fill this in for PIC32
#else
#error "This chip is not supported!"
#endif
@@ -149,6 +158,8 @@ inline void setPWM2(uint8_t s) {
#elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
// on arduino mega, pin 11 is now PB5 (OC1A)
OCR3C = s;
+#elif defined(__PIC32MX__)
+/// TODO: Fill this in for PIC32
#else
#error "This chip is not supported!"
#endif
@@ -170,6 +181,8 @@ inline void initPWM3(uint8_t freq) {
TCCR4B = (freq & 0x7) | _BV(WGM12);
//TCCR4B = 1 | _BV(WGM12);
OCR4A = 0;
+#elif defined(__PIC32MX__)
+/// TODO: Fill this in for PIC32
#else
#error "This chip is not supported!"
#endif
@@ -187,6 +200,8 @@ inline void setPWM3(uint8_t s) {
#elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
// on arduino mega, pin 6 is now PH3 (OC4A)
OCR4A = s;
+#elif defined(__PIC32MX__)
+/// TODO: Fill this in for PIC32
#else
#error "This chip is not supported!"
#endif
@@ -210,6 +225,8 @@ inline void initPWM4(uint8_t freq) {
TCCR3B = (freq & 0x7) | _BV(WGM12);
//TCCR4B = 1 | _BV(WGM12);
OCR3A = 0;
+#elif defined(__PIC32MX__)
+/// TODO: Fill this in for PIC32
#else
#error "This chip is not supported!"
#endif
@@ -227,6 +244,8 @@ inline void setPWM4(uint8_t s) {
#elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
// on arduino mega, pin 6 is now PH3 (OC4A)
OCR3A = s;
+#elif defined(__PIC32MX__)
+/// TODO: Fill this in for PIC32
#else
#error "This chip is not supported!"
#endif
diff --git a/AFMotor.h b/AFMotor.h
index 3b954a5..6f3d99b 100644
--- a/AFMotor.h
+++ b/AFMotor.h
@@ -2,25 +2,45 @@
// copyright Adafruit Industries LLC, 2009
// this code is public domain, enjoy!
+// <BPS> 09/15/2012 Modified for use with chipKIT boards
+
#ifndef _AFMotor_h_
#define _AFMotor_h_
#include <inttypes.h>
-#include <avr/io.h>
+#if defined(__AVR__)
+ #include <avr/io.h>
+
+ //#define MOTORDEBUG 1
+
+ #define MICROSTEPS 16 // 8 or 16
-//#define MOTORDEBUG 1
+ #define MOTOR12_64KHZ _BV(CS20) // no prescale
+ #define MOTOR12_8KHZ _BV(CS21) // divide by 8
+ #define MOTOR12_2KHZ _BV(CS21) | _BV(CS20) // divide by 32
+ #define MOTOR12_1KHZ _BV(CS22) // divide by 64
-#define MICROSTEPS 16 // 8 or 16
+ #define MOTOR34_64KHZ _BV(CS00) // no prescale
+ #define MOTOR34_8KHZ _BV(CS01) // divide by 8
+ #define MOTOR34_1KHZ _BV(CS01) | _BV(CS00) // divide by 64
+
+#elif defined(__PIC32MX__)
+ /// TODO: Update this for PIC32 microstepping
+ //#define MOTORDEBUG 1
-#define MOTOR12_64KHZ _BV(CS20) // no prescale
-#define MOTOR12_8KHZ _BV(CS21) // divide by 8
-#define MOTOR12_2KHZ _BV(CS21) | _BV(CS20) // divide by 32
-#define MOTOR12_1KHZ _BV(CS22) // divide by 64
+ #define MICROSTEPS 16 // 8 or 16
-#define MOTOR34_64KHZ _BV(CS00) // no prescale
-#define MOTOR34_8KHZ _BV(CS01) // divide by 8
-#define MOTOR34_1KHZ _BV(CS01) | _BV(CS00) // divide by 64
+ #define MOTOR12_64KHZ 1 // no prescale
+ #define MOTOR12_8KHZ 2 // divide by 8
+ #define MOTOR12_2KHZ 3 // divide by 32
+ #define MOTOR12_1KHZ 4// divide by 64
+
+ #define MOTOR34_64KHZ 5 // no prescale
+ #define MOTOR34_8KHZ 6 // divide by 8
+ #define MOTOR34_1KHZ 7 // divide by 64
+#endif
+// Bit positions in the 74HCT595 shift register output
#define MOTOR1_A 2
#define MOTOR1_B 3
#define MOTOR2_A 1
@@ -30,11 +50,13 @@
#define MOTOR3_A 5
#define MOTOR3_B 7
+// Constants that the user passes in to the motor calls
#define FORWARD 1
#define BACKWARD 2
#define BRAKE 3
#define RELEASE 4
+// Constants that the user passes in to the stepper calls
#define SINGLE 1
#define DOUBLE 2
#define INTERLEAVE 3
@@ -58,7 +80,7 @@
#define SER_PORT PORTB
*/
-// Arduino pin names
+// Arduino pin names for interface to 74HCT595 latch
#define MOTORLATCH 12
#define MOTORCLK 4
#define MOTORENABLE 7
@@ -76,7 +98,7 @@ class AFMotorController
class AF_DCMotor
{
public:
- AF_DCMotor(uint8_t motornum, uint8_t freq = MOTOR34_8KHZ);
+ AF_DCMotor(uint8_t motornum, uint8_t freq = MOTOR34_8KHZ);
void run(uint8_t);
void setSpeed(uint8_t);