Jump to content

NathanPiasco

Members
  • Content Count

    2
  • Joined

  • Last visited

About NathanPiasco

  • Rank
    Noob Class

Contact Methods

  • Website URL
    http://ai-mergence.com

Profile Information

  • Location
    France
  • Interests
    Robotique
  1. NathanPiasco

    [MSP432] Servo librairy conflicting with PWM analogWrite

    Hi Robert, Thank you for your answer. Here the servo code: volatile int i = 90; volatile boolean raise = true; void setup_turret() { T0.attach(turretPin_0); T1.attach(turretPin_1); T0.write(90); T1.write(90); } void loop_turret() { if ((i < T1_cmd_max)&&(raise)) { T1.write(i); i = i + 5; } else if ((i >T1_cmd_min)&&(!raise)) { T1.write(i); i = i - 5; } if (i == T1_cmd_min) raise = true; if (i == T1_cmd_max) raise =false; #if DEBUG_TURRET Serial.print("T0 : "); Serial.print("90"); Serial.print(" \t "); Serial.print("T1 : "); Serial.print(i); Serial.println(" "); #endif delay(100); } We control two motors using a H bridge, so we send four PWMs. Here a code used for debuging: analogWrite(motor_R_Forward, 255); //v_R_for); // ~490 Hz analogWrite(motor_R_Backward, 0); //v_R_back); // ~490 Hz analogWrite(motor_L_Forward, 255); //v_L_for); // ~490 Hz analogWrite(motor_L_Backward, 0); //v_L_back); // ~490 Hz And the file used to define pin numbers: // Common Libraries #include <math.h>#include <Servo.h> ///////////////// Debug Prints /////////////////#define DEBUG_DODGE 0 // Print dodge results#define DEBUG_MOTOR1 1 // Print motor command sent (-1 -> 1)#define DEBUG_MOTOR2 1 // Print motor command sent (back 0->1, front 0->1)#define DEBUG_US 0 // Print distance detected by US sensors #define DEBUG_PHOTO 0 // Print Command send by photosensors #define DEBUG_SETPOINT 0 // Print vector command sent#define DEBUG_TURRET 0 // Print agnle sent to turret///////////////////// Pins /////////////////////// Motor Pins #define motor_R_Forward 31 // P3_7 #define motor_R_Backward 32 //P3_5 #define motor_L_Forward 4 //P3_3#define motor_L_Backward 3 //P3_2// turret pins #define turretPin_0 18 //P3_6#define turretPin_1 11 //P3_0// Turret parameters Servo T0; // create servo object to control down servo Servo T1; // create servo object to control up servo #define T1_cmd_min 30 // (
  2. Hi, Sorry for the repost, I save my preview topic in the wrong place I think (http://forum.43oh.com/topic/9286-msp432-servo-librairy-conflicting-with-pwm-analogwrite/, if someone can delete this one...). I am using an MSP432P401R launchpad Rev B with Energia 17 on Windows 10. I've recently got this issue: I can't control servomotors with the Servo.h librairy and at the same time send several PWM. As soon as I called the "attach" function from Servo, the others call to analogWrite in my code don't work anymore. I think it is due to some timer conflicts (both functions using A0 timer ?), but I can't figured out how to fix the problem. I see something wierd in the Servo librairy code (in Servo.cpp:72): //timerParams.clockSource = Timer_Source_SMCLK; This instruction, that seems to choose the timer to use, is commented. Moreover I noticed that several defined are not used in the code of Servo (from Servo.h): #define SERVO_TIMER TIMERA0_BASE #define SERVO_TIME_CFG TIMER_CFG_B_PERIODIC | TIMER_CFG_SPLIT_PAIR #define SERVO_TIMER_TRIGGER TIMER_TIMB_TIMEOUT #define SERVO_TIMER_INTERRUPT INT_TIMERA0B #define SERVO_TIMER_AB TIMER_B #define SERVO_TIMER_PERIPH PRCM_TIMERA0 I have tried to modify "A0" by "A1" without success. Did someone run in a similare problem and could give me some clue to fix it ? Thanks Nathan
×