-
Notifications
You must be signed in to change notification settings - Fork 116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Drift #68
Comments
Hi, Overwhelming the Arduino with too many interrupts is definitely possible and if that happens, crashing the processor and not only missing steps is a very real possibility. But, as you mentioned, if two interrupts happen at once (an encoder and step pulse for example) one might be ignored. Well, I do not know if that is the case but it should not be. I have not tested myself but I would expect the two events would be taken care of (assuming there is plenty of time before new interrupts). But if a second interrupt happens before the first one has been handled that is for sure mean a pulse in not recorded. Could you please check what is the case? |
556/5000 the big difference for me i only use a memory value for the deviating position, the motor works infinitely, nothing overflows. |
$regfile = "m328pdef.dat" Config Portb.5 = Output 'LED Config Portd.4 = Input 'Encoder A Config Portd.2 = Input 'Step INT0 Dim Encounter As integer Config Timer1 = Pwm , Pwm = 8 , Prescale = 1 , Compare A Pwm = Clear Up ', Compare B Pwm = Clear Down Config Int1 = Change Anf: Encounter2 = Encounter if p <> Pind.2 then IF Encounter2 > 123 then Encounter2 = 123 'bei DC Motor Getencoder: '4Fachauswertung, wenn nicht nötig, besser wie Pusls aufbauen = schneller Puls: |
Hi, If the interrupt rate is high enough, the processor may run out of stack space and that may crash it. Alternately, if no nested interrupts, a high-enough interrupt rate may prevent the main program to run, so only interrupt code is executed, which looks like the processor is doing nothing. Several sources of concern:
|
Thank you very much, you looked at my code very well and took your time :-) I tested 2 variants, all 2 are included in the code.
Encounter variable only contains the deviating steps, (should-is) if 2000 steps are full, the motor is 400 revolutions wrong, if Encounter is 0 then the motor is exactly aligned. only limited the overflow. encounter2 is only because the int can interrupt the main program at any time and does not already calculate half of it with a new value, bascom reacts to Int like this: the program is interrupted at every possible point, all incoming int are ignored (blind), the code of the int is processed, the int are reactivated, the main program continues, I think this is due to the avr, this has only 1 core, so it is definitely the same with arduino, no idea about the stm32 but encoder impulses and step signals sometimes come at the same time, just coincidentally. |
STM32 timers can work in very interesting ways, like quadrature inputs, so
you timer can run at hardware speed (Mhz, that is millions of pulses per
second) without the main program being interrupted.
But even if you do not use that feature for the encoder, interrupt response
and processing speed is miles away from Arduino, so you would have system
bottleneck further away.
My guess is that most of your problems are related to a too high interrupt
rate for the Arduino, consider lowering encoder resolution and pulse signal
max frequency (or go to a more capable platform). Cheapest STM32 is blue
pill (less than $3) and a better one is Black Pill ($3-$5 depending if you
go to f401 or f411). There is even microBASIC for them too.
…On Mon, May 4, 2020 at 4:44 PM TheGermanIng ***@***.***> wrote:
Thank you very much, you looked at my code very well and took your time :-)
I am very interested in a solution, arduino software is new to me, I have
been working with bascom for decades, but my area of expertise is
hardware, when I have printed circuit boards I can send you some,
I tested 2 variants, all 2 are included in the code.
1. the int pulse: (this is part of the program is currently not
active, "Enable Int0" is missing) that's how your prog works, I think
2. alternative in the "Anf:" loop, this works better, but the "Anf"
loop has to run fast, I have no time for ki, kd or other
Encounter variable only contains the deviating steps, (should-is) if 2000
steps are full, the motor is 400 revolutions wrong, if Encounter is 0 then
the motor is exactly aligned. only limited the overflow.
encounter2 is only because the int can interrupt the main program at any
time and does not already calculate half of it with a new value,
bascom reacts to Int like this: the program is interrupted at every
possible point, all incoming int are ignored (blind), the code of the int
is processed, the int are reactivated, the main program continues,
I think this is due to the avr, this has only 1 core, so it is definitely
the same with arduino, no idea about the stm32 but encoder impulses and
step signals sometimes come at the same time, just coincidentally.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#68 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AADRZSBKOZTID2PJI3QIKGDRP3IDJANCNFSM4MYBTFVA>
.
|
or splurge and get a ~$13 NUCLEO-F411RE, it includes a proper debugger and Arduino compatible pinout if that's needed |
ok, i ordered 5 boards and a programmer, my first 32bit and 3.3V :-) |
I did a STM32 Bluepill version of dcservo that uses hardware timers for reading quad encoders. It is in my repository (I made some mistakes in pin selections when designing my PCB which led me to only using 2 of 3 axes on hardware timers). |
@TheGermanIng Please note the work made by @paukstelis did pack three axes on a single Bluepill. |
I tested a little more: Config Portd.7 = Output 'step anf: Do waitms 1500 that turns the motor back and forth 10 revolutions, each time a little further, you can see that very well on your "A" display, if I make it even worse, anf: Do on the oszi you can see that well, through you i am learning something arduino now :-) |
I am not sure I follow you: Is your test code acting as a controller
providing steps (portd.7) and direction (portd.6)?
…On Wed, May 6, 2020 at 8:24 PM TheGermanIng ***@***.***> wrote:
I tested a little more:
your program loses 1 step with every change of direction,
my testprogram on the signal source board is very simple:
Config Portd.7 = Output 'step
Config Portd.6 = Output 'dir
Dim puls As long
waitms 500
anf:
puls = 0
Do
Portd.7 = 1
waitus 25
Portd.7 = 0
waitus 25
incr puls
Loop Until puls = 7200
waitms 1500
toggle portd.6
waitms 5
goto anf
that turns the motor back and forth 10 revolutions, each time a little
further, you can see that very well on your "A" display,
if I make it even worse,
I only go 1 step forward and one step back, the motor begin turns. if I
write later without pulse x0 it will hit zero again.
anf:
puls = 0
Do
Portd.7 = 1
waitus 25
Portd.7 = 0
waitus 25
incr puls
Loop Until puls = 1
waitms 15
toggle portd.6
waitms 5
goto anf
on the oszi you can see that well,
through you i am learning something arduino now :-)
I also ordered STM8S003F3P6 test board, not only the STM32, I found it is
in all cheap china tool, voltmeter for 1 € etc.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#68 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AADRZSDJ3S7M5CV6ABYNNWTRQGTNPANCNFSM4MYBTFVA>
.
|
yes, exactly as it is a cnc or gbrl or 3d source, If I do the whole thing with 5 pulses: I can only measure that, it has nothing to do with high speed. I am happy that there are no problems with the encoder, I have tested a lot, it always counts correctly. my encoder has an index signal with led, i can see very well. x and motor position match. |
It is unclear to me what is the initial value of portd.7
Please note pulses are counted on the rising edge.
…On Thu, May 7, 2020 at 1:15 PM TheGermanIng ***@***.***> wrote:
yes, exactly as it is a cnc or gbrl or 3d source,
if you use it e.g. 0.1mm would go back and forth long time.
I switch the direction signal left, send 1 pulse, switch direction right
send 1 pulse,
I expect the motor to move back and forth between 2 positions or not to do
anything because the deviation is so small, but x counts 1 up every time,
but not down again.
If I do the whole thing with 5 pulses:
I switch the direction signal left, send 5 pulse, switch direction right
send 5 pulse, I expect the motor to move back and forth between 2
positions, but x counts 5 each time, but only 4 down.
I can only measure that, it has nothing to do with high speed.
I am happy that there are no problems with the encoder, I have tested a
lot, it always counts correctly. my encoder has an index signal with led, i
can see very well. x and motor position match.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#68 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AADRZSF2B3V7TBFEXEJY4ZLRQKIHRANCNFSM4MYBTFVA>
.
|
hi, |
if you use CHANGE each pulse causes two interrupts:: one on the rising and one on the falling edge.
RISING will only create one interrupt per pulse and this is what I do in my code:
https://github.com/misan/dcservo/blob/master/dcservoProMicro.ino#L64
Have you seen it done otherwise?
|
i test dcServoProtection.ino every time, have this drift problem, |
Ok, thanks for pointing this out. Unfortunately, it was a mistake on my code. It should have said RISING instead of CHANGE. It is fixed now. https://github.com/misan/dcservo/blob/master/dcServoProtection.ino#L62 |
Now that I review the code of countStep I can see there is something I quite do not understand that could be causing you some more trouble: there is a "compensation" here So, in fact, a pulse is lost in one of the direction changes (target++ and later target--). Code was contributed and I guess @sanchosk was fixing something I quite do not understand now. Please use dcServoUNO if using an Arduino UNO. |
Hi,
I wrote the same program in bascom before I found yours. I had the problem if 1 interrupts occur at the same time, encoder int at the same time with a new step int, one can be forgotten, I work up to 20 khz encoder and 10 khz step (multiplied step) I have now programmed a 2nd Arduino which e.g. 10000 steps forward and 10000 steps back I let it run for a while, after a while the position drifts. also with your program, the signals are absolutely clean. do you have any idea ?
The text was updated successfully, but these errors were encountered: