Stepper controller with 0-10V input - Page 1
Forum section: electronics / general

author: Ondre
author_rank: Unknown
timestamp: May 26, 2014, 08:10:29 pm
content: 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:new_pos = advalue * max_number_of_stepsStepping to the new Position:Code: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.CheersAndré

author: nctnico
author_rank: Super Contributor
timestamp: May 26, 2014, 08:48:27 pm
content: 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.

author: Ondre
author_rank: Unknown
timestamp: May 26, 2014, 09:03:00 pm
content: 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.

author: nctnico
author_rank: Super Contributor
timestamp: May 26, 2014, 10:35:44 pm
content: 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.

author: dannyf
author_rank: Super Contributor
timestamp: May 26, 2014, 10:57:29 pm
content: Many potential causes and cures for this. Without knowing more, it is impossible to tell.QuoteDepending 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.

author: Ondre
author_rank: Unknown
timestamp: May 27, 2014, 05:07:29 am
content: 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 meImportant 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!

author: rob77
author_rank: Super Contributor
timestamp: May 27, 2014, 07:26:41 pm
content: if it's really a issue with the integer math then what about taking a ragne 960 only ? 960/80 = 12 , nice round number1023-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.

author: Ondre
author_rank: Unknown
timestamp: June 03, 2014, 10:39:40 am
content: 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.Thanks for your help anyway. I'm glad it's working now.