Author Topic: Stepper controller with 0-10V input  (Read 4438 times)

0 Members and 1 Guest are viewing this topic.

Offline OndreTopic starter

  • Supporter
  • ****
  • Posts: 43
  • Country: de
Stepper controller with 0-10V input
« on: May 26, 2014, 08:10:29 pm »
Hi everyone,

I've got a Little Problem with my stepper Controller Software.

Here's what I got:
PIC18F14K22 with 0-10V analog Input (divided down to 0-3.3V)
Stepper Motor is driven by an Trinamic TMC246.

The aim: translating the Input Signal 0-10V to different Motor Positions.

The stepper Motor in General works fine. The Problem is that i'm not quite sure what's the best way to scale the AD value (0-1023) to the steps of the Motor. The Motor is supposed to do exactly x number of steps when the Input is changed from 0V to 10V.

I calculate the number of steps like this:
Code: [Select]
new_pos = advalue * max_number_of_steps

Stepping to the new Position:
Code: [Select]
if(new_pos > cur_pos) {
  do_step();
  cur_pos += 1023;
}
if(new_pos < cur_pos) {
  do_step();
  cur_pos -= 1023;
}

This appears to work accurately, but since there is always a bit of difference between new_pos and cur_pos, the Motor keeps on moving back and forth. When I insert a threshold, inside the if-statements, it appears that i'm losing some steps along the way.

Any tip on this Topic would be really appreciated. I think i'm just missing something very obvious here...dang..already 10pm and i'm still in the Office and the bloody IE keeps Messing up my spelling.

Cheers
André
 

Offline nctnico

  • Super Contributor
  • ***
  • Posts: 27217
  • Country: nl
    • NCT Developments
Re: Stepper controller with 0-10V input
« Reply #1 on: May 26, 2014, 08:48:27 pm »
Microchip is not the best choice for accurate analog parts. Read the specification for the ADC very carefully and lookup what the terms mean. The best chance you have is to oversample / filter the signal (with a boxcar filter for example) in order to try to reduce the noise if you don't want to change the circuit. Otherwise change the circuit to use an external ADC.
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline OndreTopic starter

  • Supporter
  • ****
  • Posts: 43
  • Country: de
Re: Stepper controller with 0-10V input
« Reply #2 on: May 26, 2014, 09:03:00 pm »
ADVALUE is already an averaged value of AD converter. Didn't mention that here, sorry. So the value should be pretty stable. I'm so close to connecting a serial interface to micro to see what's really going on there. I almost spent the whole day on that stupid problem.
 

Offline nctnico

  • Super Contributor
  • ***
  • Posts: 27217
  • Country: nl
    • NCT Developments
Re: Stepper controller with 0-10V input
« Reply #3 on: May 26, 2014, 10:35:44 pm »
I usually add some kind of DAC or PWM output when doing DSP(-ish) things with a microcontroller. It helps to output signals so you can check with a scope. IMHO it is still quite optimistic to get 1023 steps from a 10V signal. The noise must be less than 5mV. This will take some analog layout skills as well.
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: Stepper controller with 0-10V input
« Reply #4 on: May 26, 2014, 10:57:29 pm »
Many potential causes and cures for this. Without knowing more, it is impossible to tell.

Quote
When I insert a threshold, inside the if-statements, it appears that i'm losing some steps along the way.

Depending on how it is implemented, particularly how cur_position is updated: ideally, you have a position sensor and you read the position sensor before each comparison. Otherwise, you should only update cur_position, with new_position, not incrementally, after you have detected sufficient difference between cur_position and new_position.
================================
https://dannyelectronics.wordpress.com/
 

Offline OndreTopic starter

  • Supporter
  • ****
  • Posts: 43
  • Country: de
Re: Stepper controller with 0-10V input
« Reply #5 on: May 27, 2014, 05:07:29 am »
Ok, I have to explain the whole thing in a bit more detail when I'm back in the office. I was quite late last night when I wrote the post and SWMBO was already angry with me  :P

Important information: The motor has to do only 80 (twice that number for a different type of application) steps. So there shouldn't be a problem with noise and the resolution of the A/D. 1023 / 80 = 12,7875.

And that's what I think the problem lies: 1023 / 80 is not a whole number. I can't do 12,7875 steps per increment. When I calculate the number of steps for the motor based on the change of the input signal, I end up with some "rounding" error. Doing several small increments doesn't give me the same number of steps as doing one large increment. I'll post an example later...

Thanks for your help so far!
 

Offline rob77

  • Super Contributor
  • ***
  • Posts: 2085
  • Country: sk
Re: Stepper controller with 0-10V input
« Reply #6 on: May 27, 2014, 07:26:41 pm »
if it's really a issue with the integer math then what about taking a ragne 960 only ? 960/80 = 12 , nice round number ;)
1023-960 = 63 ... so for example  substract 31 from the adc readings and clamp it to 960 max - you will have small dead spots on the potenciometer at the begining and the end, but that could be acceptable i think.
 

Offline OndreTopic starter

  • Supporter
  • ****
  • Posts: 43
  • Country: de
Re: Stepper controller with 0-10V input
« Reply #7 on: June 03, 2014, 10:39:40 am »
Geeeez! I finally found time to get back to the problem. I've connected an a serial interface for debugging to my circuit and that finally gave me the clue. There was no problem with data from the A/D. I feel a bit stupid now, but it turned out, that the pointers to array containing the phase current values for the stepper motor wasn't correclty initialized. So the motor worked fine while doing multiple steps, but occasially skipped a step while doing single steps at a time.  Double face palm.  :palm: :palm:

Thanks for your help anyway. I'm glad it's working now.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf