Quantcast
Channel: Motor drivers forum - Recent Threads
Viewing all articles
Browse latest Browse all 14309

CCS/DRV8838: how can I know the speed of the motor?

$
0
0

Part Number: DRV8838

Tool/software: Code Composer Studio

Hello, 

I want to use PID to make sure the speed of the motors can maintain at the same value, but I don't know how to get the speed of the DRV8838 and DRV8837 motors, probably it's related to rising and the falling edges, right? I guess I need to get how much time it takes for each spin first, but I'm also confused about this.

Also, I don't know how to control the speed of the motors, I tried changing pwmPeriod, but it seems that the motor runs at the same speed. 

I think the code below might help me solve this problem, but I don't know how to get the speed and the current time.

void RHMotorChannelAFallingFxn(unsigned int index)
{
if (GPIO_read(MSP_EXP432P401R_P6_1)){
… do something …
}

else{
… do something …
}}

void RHMotorChannelARisingFxn(unsigned int index)
{

if (GPIO_read(MSP_EXP432P401R_P4_0)){
… do something …
}

else{
… do something …
}}

GPIO_setCallback(MSP_EXP432P401R_P6_1, RHMotorChannelAFallingFxn);
GPIO_enableInt(MSP_EXP432P401R_P6_1);
GPIO_setCallback(MSP_EXP432P401R_P4_0, RHMotorChannelARisingFxn);
GPIO_enableInt(MSP_EXP432P401R_P4_0);

The code below I used can run the motors, but the speed is the same even though I changed the pwmPeriod:

Void MotorFxn(UArg arg0, UArg arg1)
{
PWM_Handle pwm1;
PWM_Handle pwm2;
PWM_Handle pwm3;
PWM_Handle pwm4;
PWM_Params params;
uint16_t pwmPeriod = 9000; // Period and duty in microseconds
uint16_t duty = 0;
uint16_t dutyInc = 100;

PWM_Params_init(&params);
params.dutyUnits = PWM_DUTY_US;
params.dutyValue = 0;
params.periodUnits = PWM_PERIOD_US;
params.periodValue = pwmPeriod;

GPIO_write(Robot_MotorEN, Robot_Motor_ON );

pwm1 = PWM_open(Board_PWM0, &params);
if (pwm1 == NULL) {
System_abort("Board_PWM1 did not open");
}
PWM_start(pwm1);

pwm2 = PWM_open(Board_PWM1, &params);
if (pwm2 == NULL) {
System_abort("Board_PWM2 did not open");
}
PWM_start(pwm2);

pwm3 = PWM_open(Board_PWM2, &params);
if (pwm3 == NULL) {
System_abort("Board_PWM3 did not open");
}
PWM_start(pwm3);

pwm4 = PWM_open(Board_PWM3, &params);
if (pwm4 == NULL) {
System_abort("Board_PWM4 did not open");
}
PWM_start(pwm4);


PWM_setDuty(pwm1, 0);
PWM_setDuty(pwm2, pwmPeriod);
PWM_setDuty(pwm3, 0);
PWM_setDuty(pwm4, pwmPeriod);

Task_sleep((UInt) arg0);
}

Thanks for any help.


Viewing all articles
Browse latest Browse all 14309

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>