MECHATRONICS question!

Thread Starter

MaxHeadRoom

Joined Jul 18, 2013
24,991
I am assuming this is just simple 32 bit arithmetic functions.?
Max.

C:
; 
unsigned char rpos
unsigned long bres

// 2. updates reference freq generator, records its position
  bres += 102400;                 ; add nS per interrupt period (512 insts * 200nS)
  if(bres >= MOTOR_PULSE_PERIOD)  ; if reached a new reference step
  {
    bres -= MOTOR_PULSE_PERIOD;
    rpos++;                       ; record new xtal-locked reference position
  }
 

AlbertHall

Joined Jun 4, 2014
11,953
Max, what is wrong with using the existing program and XC8 (free)? The changes for the compiler will be minimal, possibly limited to setting up the some lines for the config fuses and the program details what the values should be.
 

philba

Joined Aug 17, 2017
959
What would the assembly version of this be?
Max.

C:
;  2. updates reference freq generator, records its position
  bres += 102400;                 ; add nS per interrupt period (512 insts * 200nS)
  if(bres >= MOTOR_PULSE_PERIOD)  ; if reached a new reference step
  {
    bres -= MOTOR_PULSE_PERIOD;
    rpos++;                       ; record new xtal-locked reference position
  }
Nothing esoteric. Perhaps some of the C operators confuse.
a += b is the same as a = a + b,
a -= b is the same as a = a - b
a++ is the same as a = a + 1

I think you've got the comparisons figured already.

I do find the use of bresenham's line drawing algorithm somewhat clever in it's simplicity but I think a simple PID approach could be better (smoother) though probably a lot more code. As it is, his approach is basically only I as he controls the error accumulation.
 

cmartinez

Joined Jan 17, 2007
7,629
Anyone done any motor control design using Roman's methods here https://www.romanblack.com/onesec/DCmotor_xtal.htm
I am toying with the idea of variable control, but have to convert his program to Assembly if possible.
(was a forum member The_RB).
Max.
Wow... this guy is using Bresenham's algorithm to derive different frequencies from a master one! ... it's genius! ... Why didn't I think of that before? ... this could've come in handy in a previous project of mine. I'm gonna start studying his code and see if I can adapt it to my purposes.

Thanks for posting, Max.
 

philba

Joined Aug 17, 2017
959
Bresenham 's basic algorithm has a lot of applications. The use of accumulated error to get within 1 discreet point via add/subtract is brilliant in it's simplicity. I use it to do temporal transitions between colors. A compare and 2 adds per step is all it takes. Sadly, he never got a dime for it.
 

Thread Starter

MaxHeadRoom

Joined Jul 18, 2013
24,991
I think this application could be made easier by replacing the 16F628a with a INT on-input type, and even go to the 18F series and replace the quadrature reading head method.
Also the possibility of making it more flexible in setting various RPM's.
Max.
 
Top