Permalink
Browse files

snootor dc working

  • Loading branch information...
1 parent 250d933 commit d424cc28c5dcbd681782a8a3e6089ac8bd38b958 Ikujam committed Oct 7, 2011
Showing with 62 additions and 14 deletions.
  1. +17 −0 snootor.cpp
  2. +2 −1 snootor_common.h
  3. +41 −9 snootor_dc.cpp
  4. +1 −0 snootor_dc.h
  5. +1 −0 snootor_motor.h
  6. +0 −4 snootor_step.cpp
View
17 snootor.cpp
@@ -23,9 +23,25 @@
Snootor::Snootor(){
motor_state=0;
maxstate=0;
+ /**
+ * keep track of "directions"
+ **/
+ _regvalue=0xff;
+
}
+void Snootor::enableMax(void) {
+ if(maxstate==0){
+ maxstate=1;
+ i2c( 0x6, 0x00); // input and output config.
+ i2c( 0x2, 0x00); // input and output config.
+ }
+#ifdef MOTOR_DEBUG
+ Serial.println("MAX7313 I2C INIT DONE !");
+#endif
+}
+/*
void Snootor::enableMax(void) {
// following setup is test purpose, try to improve it with mixed output style
@@ -52,6 +68,7 @@ void Snootor::enableMax(void) {
#endif
}
+*/
/**
*
View
3 snootor_common.h
@@ -13,7 +13,7 @@
// activates debug mode :
-//#define MOTOR_DEBUG
+#define MOTOR_DEBUG
#include "snootor_motor.h"
@@ -40,6 +40,7 @@ class Snootor{
Snootor();
~Snootor(){}
void delay(uint32_t); // scheduler
+ uint8_t _regvalue;
#ifdef MOTOR_DEBUG
void dump(); // debug information for each motor
#else
View
50 snootor_dc.cpp
@@ -10,6 +10,15 @@
+/**
+ * binary mask for motor control
+ *
+ **/
+static uint8_t mask_forw[]={0xFE,0xFB,0xEF,0xBF}; // bit-by-bit "and" operation,
+static uint8_t mask_back[]={0xFD,0xF7,0xDF,0x7F}; // bit-by-bit "and" operation,
+static uint8_t mask_rel[] ={0x03,0x0C,0xC0,0x30}; // bit-by-bit "or" operation,
+
+
/******************************************
@@ -196,23 +205,46 @@ void SnootorDC::init(uint8_t num,uint8_t freq) {
}
SnootorDC* SnootorDC::run(uint8_t cmd) {
+
+#ifdef MOTOR_DEBUG
+ Serial.print("before run : ");
+ Serial.println(SC._regvalue,HEX);
+#endif
+
switch (cmd) {
case FORWARD:
- if(!inverted)
- SC.i2c(registry,0x0f);
- else
- SC.i2c(registry,0xf0);
+ if(!inverted){
+ SC._regvalue = SC._regvalue & mask_forw[motornum-1];
+ // SC.i2c(registry,0x0f);
+ }
+ else{
+ SC._regvalue = SC._regvalue & mask_back[motornum-1];
+ // SC.i2c(registry,0xf0);
+ }
break;
case BACKWARD:
- if(!inverted)
- SC.i2c(registry,0xf0);
- else
- SC.i2c(registry,0x0f);
+ if(!inverted){
+ SC._regvalue = SC._regvalue & mask_back[motornum-1];
+ // SC.i2c(registry,0xf0);
+ }
+ else{
+ SC._regvalue = SC._regvalue & mask_forw[motornum-1];
+ // SC.i2c(registry,0x0f);
+ }
break;
case RELEASE:
- SC.i2c(registry,0x0);
+ SC._regvalue = SC._regvalue | mask_rel[motornum-1];
+ // SC.i2c(registry,0x0);
break;
}
+
+#ifdef MOTOR_DEBUG
+ Serial.print("after run : ");
+ Serial.println(SC._regvalue,HEX);
+#endif
+
+ // SC._regvalue=M4_MASK_FORW & M3_MASK_FORW ;
+ SC.i2c(0x02,SC._regvalue);
return this;
}
View
1 snootor_dc.h
@@ -15,6 +15,7 @@
#include "snootor_defines.h"
#include "snootor_common.h"
+#include "snootor_motor.h"
#ifndef __SNOOTOR_DC_H
#define __SNOOTOR_DC_H
View
1 snootor_motor.h
@@ -25,6 +25,7 @@
class SnootorMotor{
public:
+
SnootorMotor(){}
virtual uint16_t next(){} // checks if action is needed, otherwise quits (for stepper)
View
4 snootor_step.cpp
@@ -180,19 +180,15 @@ uint16_t SnootorStep::halfstep(){
case 1:
SC.i2c2(motor_regA,0x0F,motor_regC,0xF0); //C,+A-
break;
-
case 2:
SC.i2c2(motor_regA,0x0F,motor_regC,0x0); //C0,A-
break;
-
-
case 3:
SC.i2c2(motor_regA,0x0F,motor_regC,0x0F); //C-,A-
break;
case 4:
SC.i2c2(motor_regA,0x0,motor_regC,0x0F); //C-,A0
break;
-
case 5:
SC.i2c2(motor_regA,0xF0,motor_regC,0x0F); //C-,A+
break;

0 comments on commit d424cc2

Please sign in to comment.