Teensy 3.x with LabVIEW & teensyduino & LIFA

Status
Not open for further replies.

Mark

Well-known member
Got 2.0 working on my setup. Started messing with 3.1 in the same thread, but couldn't figure to rename the thread. (if someone tells how I'll delete this one - if possible)

Starting at here in the old thread:
http://forum.pjrc.com/threads/25055...syduino-amp-LIFA?p=41476&viewfull=1#post41476

Now chasing these errors.
****************
In file included from AFMotor.cpp:13:0:
AFMotor.h:134: error: 'CS01' was not declared in this scope
AFMotor.cpp: In constructor 'AF_Stepper::AF_Stepper(uint16_t, uint8_t)':
AFMotor.cpp:310: error: 'CS20' was not declared in this scope
****************
I suspect these will require Arduino lib mods, not LIFA mods, so might need fixes in Teensyduino? If I find 'fixes', I'll post in this thread.
 
Took inspiration from the latest AFMotor from Adafruit and modded the AFMotor.h file to check for the arm processor. It Compiles! Of course, I haven't been able to get it working on 3.1 - yet.

One thing I know is likely bogus (place holders only) is the PWM rates (MOTOR12_64KHZ, et al). I'll search the forums and files to see how the FTM clock is run, but if someone has input, I won't mind. :)

I also reworked the blink.vi with controls for different boards (LED pin changes), serial port picking, and documentation blocks.

I can put the changes up on my Git, or if there's another preferred way to share here, let me know.
 
AFMotor.h - modded


Code:
// Adafruit Motor shield library
// copyright Adafruit Industries LLC, 2009
// this code is public domain, enjoy!

#ifndef _AFMotor_h_
#define _AFMotor_h_

#include <inttypes.h>

#if defined(__AVR__)
    #include <avr/io.h>
  
    //#define MOTORDEBUG 1
    
    #define MICROSTEPS 16         // 8 or 16
    
    #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 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(__arm__)
    #include <avr/io.h>

    //#define MOTORDEBUG 1
    
    // I'm fairly certain these are wrong! - Mark
    #define MICROSTEPS 16         // 8 or 16
    
    #define MOTOR12_64KHZ   1     // no prescale
    #define MOTOR12_8KHZ    8     // divide by 8
    #define MOTOR12_2KHZ    32    // divide by 32
    #define MOTOR12_1KHZ    64    // divide by 64
    
    #define MOTOR34_64KHZ   1     // no prescale
    #define MOTOR34_8KHZ    8     // divide by 8
    #define MOTOR34_1KHZ    64  // divide by 64*/

#endif


#define MOTOR1_A 2
#define MOTOR1_B 3
#define MOTOR2_A 1
#define MOTOR2_B 4
#define MOTOR4_A 0
#define MOTOR4_B 6
#define MOTOR3_A 5
#define MOTOR3_B 7

#define FORWARD 1
#define BACKWARD 2
#define BRAKE 3
#define RELEASE 4

#define SINGLE 1
#define DOUBLE 2
#define INTERLEAVE 3
#define MICROSTEP 4

/*
#define LATCH 4
#define LATCH_DDR DDRB
#define LATCH_PORT PORTB

#define CLK_PORT PORTD
#define CLK_DDR DDRD
#define CLK 4

#define ENABLE_PORT PORTD
#define ENABLE_DDR DDRD
#define ENABLE 7

#define SER 0
#define SER_DDR DDRB
#define SER_PORT PORTB
*/

// Arduino pin names
#define MOTORLATCH 12
#define MOTORCLK 4
#define MOTORENABLE 7
#define MOTORDATA 8
// Arduino pins used for PWM
// [url]https://github.com/adafruit/Adafruit-Motor-Shield-for-Arduino/raw/master/mshieldv12schem.png[/url]
#define MOTOR_PWM0A 6
#define MOTOR_PWM0B 5
#define MOTOR_PWM1A 9
#define MOTOR_PWM1B 10
#define MOTOR_PWM2A 11
#define MOTOR_PWM2B 3

#if defined(__AVR_ATmega8__) || defined(__AVR_ATmega48__) || defined(__AVR_ATmega88__) || \
    defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__) 
	#define AFMOTOR_PWM1_USE_OC2A
	#define AFMOTOR_PWM2_USE_OC2B
	#define AFMOTOR_PWM3_USE_OC0A
	#define AFMOTOR_PWM4_USE_OC0B
#elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
	#define AFMOTOR_PWM1_USE_OC1A
	#define AFMOTOR_PWM2_USE_OC3C
	#define AFMOTOR_PWM3_USE_OC4A
	#define AFMOTOR_PWM4_USE_OC3A
#endif


#if defined(__AVR_ATmega32U4__) && defined(CORE_TEENSY)
// Alternate pins when used on Teensy 2.0
	// TODO: figure out pins & timers to make this work...
	#define AFMOTOR_PWM1_NO_OUTPUT
	#define AFMOTOR_PWM2_NO_OUTPUT
	#define AFMOTOR_PWM3_NO_OUTPUT
	#define AFMOTOR_PWM4_NO_OUTPUT
#elif defined(__AVR_AT90USB1286__) && defined(CORE_TEENSY)
// Alternate pins when used on Teensy++ 2.0
	// TODO: figure out pins & timers to make this work...
	#define AFMOTOR_PWM1_NO_OUTPUT
	#define AFMOTOR_PWM2_NO_OUTPUT
	#define AFMOTOR_PWM3_NO_OUTPUT
	#define AFMOTOR_PWM4_NO_OUTPUT
#endif


#if defined(__MK20DX128__) && defined(CORE_TEENSY)
// Alternate pins when used on Teensy 3.0 - mark 2014-02-05
	// TODO: figure out pins & timers to make this work...
	#define AFMOTOR_PWM1_NO_OUTPUT
	#define AFMOTOR_PWM2_NO_OUTPUT
	#define AFMOTOR_PWM3_NO_OUTPUT
	#define AFMOTOR_PWM4_NO_OUTPUT
#elif defined(__MK20DX256__) && defined(CORE_TEENSY)
// Alternate pins when used on Teensy 3.1 - mark 2014-02-05
	// TODO: figure out pins & timers to make this work...
	#define AFMOTOR_PWM1_NO_OUTPUT
	#define AFMOTOR_PWM2_NO_OUTPUT
	#define AFMOTOR_PWM3_NO_OUTPUT
	#define AFMOTOR_PWM4_NO_OUTPUT
#endif


class AFMotorController
{
  public:
    AFMotorController(void);
    void enable(void);
    friend class AF_DCMotor;
    void latch_tx(void);
};

class AF_DCMotor
{
 public:
  AF_DCMotor(uint8_t motornum, uint8_t freq =  MOTOR34_8KHZ);
  void run(uint8_t);
  void setSpeed(uint8_t);

 private:
  uint8_t motornum, pwmfreq;
};

class AF_Stepper {
 public:
  AF_Stepper(uint16_t, uint8_t);
  void step(uint16_t steps, uint8_t dir,  uint8_t style = SINGLE);
  void setSpeed(uint16_t);
  uint8_t onestep(uint8_t dir, uint8_t style);
  void release(void);
  uint16_t revsteps; // # steps per revolution
  uint8_t steppernum;
  uint32_t usperstep, steppingcounter;
 private:
  uint8_t currentstep;

};

uint8_t getlatchstate(void);

#endif
 
Last edited:
blink.vi

blink_2014-02-12.PNG

Text in the lower block was greatly copied from somewhere. (teensyduino pin definition file?)
 
Last edited:
Played with it a bit more now. The error in LV is happening when the COM port is first being opened. Looks like the baud rate, etc, are all properly getting to the vi. This does not happen with the Teensy 2.0, so I'm thinking something is wrong in the 3.x code. <yeah, I know. DUH!> Probably an adaptation in the LIFA code, but don't know that. More peeling...

If someone has an idea how to test this simply, outside of LabVIEW, I'm all eyes. :)
 
Was able to connect with the COM port using PUTTY, but didn't get any reply/echo. Maybe because I don't know what to send the LIFA firmware, or the firmware opens the port but isn't working otherwise. <?>
 
Status
Not open for further replies.
Back
Top