Hi
Sorry, I took the connection schema of shield instead of schema of carrier.
According to the MC33926 datasheet truth table:
EN : VDD (Default- overriding jumper)
INV: VDD (Default- overriding jumper)
SLEW: VDD (Default- overriding jumper)
D1:LOW (GND) (Default- overriding jumper)
IN1: Digital output from ARDUINO
IN2: Digital output from ARDUINO
PWM / nD2: PWM output from ARDUINO
nSF: Digital input (ARDUINO)
FB: Analog input (ARDUINO)
I mad this modifications in the library:
#include "DualMC33926MotorShield.h"
// Constructor ////////////////////////////////////////////////////////////////
DualMC33926MotorShield::DualMC33926MotorShield(unsigned char M1IN1, unsigned char M1IN2, unsigned char M1PWM, unsigned char M1FB, unsigned char M2IN1, unsigned char M2IN2, unsigned char M2PWM, unsigned char M2FB, unsigned char nSF)
{
//Pin map
_M1IN1 = M1IN1;
_M1IN2 = M1IN2;
_M1PWM = M1PWM;
_M1FB = M1FB;
_M2IN1 = M2IN1;
_M2IN2 = M2IN2;
_M2PWM =M2PWM;
_M2FB = M2FB;
_nSF = nSF;
}
// Public Methods //////////////////////////////////////////////////////////////
void DualMC33926MotorShield::init()
{
// Define pinMode for the pins and set the frequency for timer1 and 3.
pinMode(_M1IN1,OUTPUT);
pinMode(_M1IN2,OUTPUT);
pinMode(_M1PWM,OUTPUT);
pinMode(_M1FB,INPUT);
pinMode(_M2IN1,OUTPUT);
pinMode(_M2IN2,OUTPUT);
pinMode(_M2PWM,OUTPUT);
pinMode(_M2FB,INPUT);
pinMode(_nSF,INPUT);
#if defined(__AVR_ATmega2560__)|| defined(__AVR_ATmega1820__)
// Timer 1 configuration
// prescaler: clockI/O / 1
// outputs enabled
// phase-correct PWM
// top of 400
//
// PWM frequency calculation
// 16MHz / 1 (prescaler) / 2 (phase-correct) / 400 (top) = 20kHz
TCCR1A = 0b10100000;
TCCR1B = 0b00010001;
ICR1 = 400;
// Timer 3 configuration
// prescaler: clockI/O / 1
// outputs enabled
// phase-correct PWM
// top of 400
//
TCCR3A = 0b10100000;
TCCR3B = 0b00010001;
ICR3 = 400;
#endif
}
// Set speed for motor 1, speed is a number betwenn -400 and 400
void DualMC33926MotorShield::setM1Speed(int speed)
{
unsigned char reverse = 0;
if (speed < 0)
{
speed = -speed; // Make speed a positive quantity
reverse = 1; // Preserve the direction
}
if (speed > 400) // Max PWM dutycycle
speed = 400;
#if defined(__AVR_ATmega2560__)|| defined(__AVR_ATmega1820__)
OCR1A = speed;
OCR3A = speed;
#else
analogWrite(_M1PWM,speed * 51 / 80); // default to using analogWrite, mapping 400 to 255
#endif
if (reverse)
{
digitalWrite(_M1IN1,HIGH);
digitalWrite(_M1IN2,LOW);
}
else
{
digitalWrite(_M1IN1,LOW);
digitalWrite(_M1IN2,HIGH);
}
}
// Set speed for motor 2, speed is a number betwenn -400 and 400
void DualMC33926MotorShield::setM2Speed(int speed)
{
unsigned char reverse = 0;
if (speed < 0)
{
speed = -speed; // Make speed a positive quantity
reverse = 1; // Preserve the direction
}
if (speed > 400) // Max PWM dutycycle
speed = 400;
#if defined(__AVR_ATmega2560__)|| defined(__AVR_ATmega1820__)
OCR1B = speed;
OCR3B = speed;
#else
analogWrite(_M2PWM,speed * 51 / 80); // default to using analogWrite, mapping 400 to 255
#endif
if (reverse)
{
digitalWrite(_M2IN1,HIGH);
digitalWrite(_M2IN2,LOW);
}
else
{
digitalWrite(_M2IN1,LOW);
digitalWrite(_M2IN2,HIGH);
}
}