Xmos Control and Robotics Development Board

XCore Project reviews, ideas, videos and proposals.
richardf
Junior Member
Posts: 5
Joined: Tue Aug 23, 2011 1:59 pm

Post by richardf »

Hi all,

I'm currently a student at Bristol University studying Computer Science and Electronics. Since the end of July I've been working basic motor control whilst on a placement at XMOS so I thought I'd update you all on what I've been doing and what I hope to have done by the end of September when I finish my placement. I've never worked with any XMOS hardware before so I've been learning a lot!

I've been working on both DC and stepper motor control using the XP-DSC-BLDC board.

So far in the five weeks I've been working on this I've implemented the following features:

Stepper Motors:
  • Microstepping (Full step to 1/256 microsteps)
    Basic current limiting, to allow driving motors at higher than their rated voltage
    Current monitoring in motor windings using the ADC

DC Motors:
  • Velocity ramping
    PWM speed control using the sc_pwm component available on github
    Quadrature encoder feedback
    PID control loop for constant speed control
I'll be tidying these up, writing some documentation and putting them into a repository on github at some point this week. Bear in mind that this is still a work in progress and some of the code may be a little rough around the edges.

I have some more ideas that I'd like to implement, mostly around stepper motors:

Closed loop PI current control with microstepping
Alternating decay modes (fast and slow)

I'll give you an update once I've put the code on github, in the meantime any feedback would be welcome.

Regards,

Richard
Last edited by richardf on Tue Aug 23, 2011 5:14 pm, edited 1 time in total.


User avatar
phalt
Respected Member
Posts: 298
Joined: Thu May 12, 2011 11:14 am
Contact:

Post by phalt »

Don't forget to make a project on XCore for it too!
User avatar
Folknology
XCore Legend
Posts: 1274
Joined: Thu Dec 10, 2009 10:20 pm
Contact:

Post by Folknology »

Wow this looks really cool Richard, can't wait to see the code on git hub.

PS I'm hoping your not relying on the external SDRAM for the velocity control stuff as am hoping for single L1 code operation.

regards
Al
richardf
Junior Member
Posts: 5
Joined: Tue Aug 23, 2011 1:59 pm

Post by richardf »

Hi Al,

With respect to the velocity control I assume you're talking about ramping profiles etc. being stored externally?

I haven't really been focusing on that aspect so currently there's only basic functionality around velocity control although I don't think it would be too hard to extend if needed.

Richard
richardf
Junior Member
Posts: 5
Joined: Tue Aug 23, 2011 1:59 pm

Post by richardf »

Hi everyone,

I've uploaded the code to github now under sw_basic_motor_control.

https://github.com/xcore/sw_basic_motor_examples

Also there is a project on xcore:

https://www.xcore.com/projects/basic-mo ... stepper-dc

I will update you as I add new features but the code is still under development so there may be a few bugs.

Hope you find this useful and any feedback is welcome.

Regards,

Richard
User avatar
Folknology
XCore Legend
Posts: 1274
Joined: Thu Dec 10, 2009 10:20 pm
Contact:

Post by Folknology »

Hey this looks good Richard

Just had a brief look through the DC control code and have a question:
out of curiosity why have you kept these timer sections seprate:

Code: Select all

case t when timerafter (time) :> void:
...
case t_pid when timerafter(time_pid) :> void:
...
If they were both in the same case it would reduce the resource (timer) consumption and it might lead to a slight optimisation. Are you doing this purposely to make it more readable or is there a benefit to this route?

regards
Al
User avatar
Folknology
XCore Legend
Posts: 1274
Joined: Thu Dec 10, 2009 10:20 pm
Contact:

Post by Folknology »

Possible optimisation of the Integrator

From:

Code: Select all

pid_I[j] = pid_I[j] + ( K_I * error[j] / ( ONE_SECOND / PID_PERIOD ) );
To:

Code: Select all

pid_I[j] += error[j]  * ( K_I / ( ONE_SECOND / PID_PERIOD ) );
Would be worth trying and looking at the assembly to see (I haven't done this).

regards
Al
richardf
Junior Member
Posts: 5
Joined: Tue Aug 23, 2011 1:59 pm

Post by richardf »

Hey Al,

Thanks for pointing out the issue with the timers, it was a remnant of an older version. I've put it all in one case now.

I'll take a look at the integrator and see if that improves things...

Thanks,

Richard

Edit: changing the integrator seemed to improve ASM so I've put updated it. Thanks Al.
User avatar
Folknology
XCore Legend
Posts: 1274
Joined: Thu Dec 10, 2009 10:20 pm
Contact:

Post by Folknology »

You could probably optmise further by moving the 120/624 rpm division over to the LCD display thread (rather than in the more critical motor thread). But the one that would have most effect on optimisation is the pid speed calc:

Code: Select all

speed_actual[j] = ( ( speed_current[j] * 100 ) + ( speed_previous[j] * 9000) ) / 10000;
if you could get rid of that runtime division, the thread would run faster and be safer on any other threads that might be running on the motor core.

Anyone got an ideas how to optimise this and its surrounding speed calcs out, perhaps using right shifts?

regards
Al
Post Reply