Estoy usando una placa estándar para controlar este tipo de motor (SimpleBGC), esta placa usa una atmeg328p e algunos controladores sin escobillas. Estoy escribiendo un código simple para girar a la izquierda / derecha con cierta velocidad, pero tengo algunos problemas. Los motores están sobrecalentados, y el par es muy bajo. El motor tiene 12 polos (polos: 12N14P), ¿cómo ajusto la frecuencia correcta de pwm para este número de polos? Y quiero entender la relación entre el número de polos y la frecuencia de los temporizadores pwm.
1) EDITAR La placa que estoy usando - enlace Esta placa utiliza un atmega328p, y para impulsar la potencia de los motores con este MOSFET 4606
El motor que estoy tratando de usar, enlace
El código
//main loop--------------------------------------------------------
#include <math.h>
#define LEDPIN A1
bool power = false; //run when power is true
uint16_t freqCounter = 0;
uint16_t oldfreqCounter = 0;
uint16_t loop_time = 0; //how fast is the main loop running
//motor control-------------------------------------------------------
#define PWM_A_MOTOR1 OCR2A
#define PWM_B_MOTOR1 OCR1B
#define PWM_C_MOTOR1 OCR1A
#define PWM_A_MOTOR0 OCR0A
#define PWM_B_MOTOR0 OCR0B
#define PWM_C_MOTOR0 OCR2B
#define RESOLUTION 255
#define MOTOR_POWER 255 // 0 to 255, 255==100% power
uint8_t idl_motor_power = 80;
// motor numbers
#define L_Motor 0
#define R_Motor 1
// motor pole angle, 0->255 overflow to loop after >>8 shift
uint16_t R_MotorStep = 0;
uint16_t L_MotorStep = 0;
float robot_speed;
//rotation speed for turning
int8_t rot_Speed = 0;
// speed of motors, -127 to 127
int16_t R_Speed = 0;
int16_t L_Speed = 0;
float R_pos = 0;
float L_pos = 0;
//AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
//------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------
//AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
void setup()
{
// Start Serial Port
Serial.begin(11520);
//Setup brushless motor Controller
Bl_Setup();
Serial.println("BL motor setup - ok");
while (Serial.available()) Serial.read(); // empty RX buffer
}
void loop()
{
//run main loop every ~4ms
R_Speed = 50;
L_Speed = 100;
}
//--------------------------------------------------------------------
//Motor control stuff-------------------------------------------------
//--------------------------------------------------------------------
void Bl_Setup()
{
pinMode(3, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
digitalWrite(LEDPIN, HIGH);
cli();//stop interrupts
//timer setup for 31.250KHZ phase correct PWM
TCCR0A = 0;
TCCR0B = 0;
TCCR0A = _BV(COM0A1) | _BV(COM0B1) | _BV(WGM00);
TCCR0B = _BV(CS00);
TCCR1A = 0;
TCCR1B = 0;
TCCR1A = _BV(COM1A1) | _BV(COM1B1) | _BV(WGM10);
TCCR1B = _BV(CS10);
TCCR2A = 0;
TCCR2B = 0;
TCCR2A = _BV(COM2A1) | _BV(COM2B1) | _BV(WGM20);
TCCR2B = _BV(CS20);
// enable Timer 1 interrupt
TIMSK1 = 0;
TIMSK1 |= _BV(TOIE1);
// disable arduino standard timer interrupt
TIMSK0 &= ~_BV(TOIE1);
sei(); // Start Interrupt
//turn off all PWM signals
OCR2A = 0; //11 APIN
OCR2B = 0; //D3
OCR1A = 0; //D9 CPIN
OCR1B = 0; //D10 BPIN
OCR0A = 0; //D6
OCR0B = 0; //D5
// switch off PWM Power
motorPowerOff();
}
// switch off motor power
void motorPowerOff() {
MoveMotors(L_Motor, 0, 0);
MoveMotors(R_Motor, 0, 0);
R_Speed = 0;
L_Speed = 0;
}
void MoveMotors(uint8_t motorNumber, uint8_t posStep, uint16_t power)
{
int16_t pwm_a;
int16_t pwm_b;
int16_t pwm_c;
pwm_a = (int16_t) 128+128*sin(2*M_PI*(double)(posStep)/RESOLUTION);
pwm_b = (int16_t) 128+128*sin(2*M_PI*(0.33+(double)(posStep)/RESOLUTION));
pwm_c = (int16_t) 128+128*sin(2*M_PI*(0.66+(double)(posStep)/RESOLUTION));
// scale motor power
pwm_a *= power/255;
pwm_b *= power/255;
pwm_c *= power/255;
// set motor pwm variables
if (motorNumber == 0)
{
PWM_A_MOTOR0 = (uint8_t)pwm_a;
PWM_B_MOTOR0 = (uint8_t)pwm_b;
PWM_C_MOTOR0 = (uint8_t)pwm_c;
}
if (motorNumber == 1)
{
PWM_A_MOTOR1 = (uint8_t)pwm_a;
PWM_B_MOTOR1 = (uint8_t)pwm_b;
PWM_C_MOTOR1 = (uint8_t)pwm_c;
}
}
//--------------------------------------------------------------
// code loop timing---------------------------------------------
//--------------------------------------------------------------
// minimize interrupt code length
// is called every 31.875us (510 clock cycles) ???????
ISR( TIMER1_OVF_vect )
{
//every 32 count of freqCounter ~1ms
freqCounter++;
if ((freqCounter & 0x01f) == 0)
{
// record when loop starts
oldfreqCounter = freqCounter;
if(R_pos>RESOLUTION) R_pos=0;
if(L_pos>RESOLUTION) L_pos=0;
MoveMotors(R_Motor, (uint8_t) R_pos, MOTOR_POWER);
MoveMotors(L_Motor, (uint8_t) L_pos, MOTOR_POWER);
R_pos+=R_Speed/20;
L_pos+=L_Speed/20;
//calculate loop time
if (freqCounter > oldfreqCounter)
{
if (loop_time < (freqCounter - oldfreqCounter)) loop_time = freqCounter - oldfreqCounter;
}
}
}