Pages: [1]   Go Down
Author Topic: Stepper motors + display number of steps  (Read 663 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 25
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
                                   void stepper()
                                            {int p = 0; int a = 0;
                                            while (digitalRead(pedaldown) == LOW) {
                                            motorstep2(1,1);
                                            p = p + 1;
                                            lcd.setCursor(0,0);
                                            a = 0.5 * p;
                                            lcd.print("Marking depth:");
                                            lcd.setCursor(8,2);
                                            lcd.print(a);
                                            lcd.setCursor(13,2);
                                            lcd.print("microns");
                                            }
                                            }

The code works ok but I have a problem. The stepper makes a step, displays the value on the lcd, takes a step again, and so on. This creates an "un-smooth" rotation of the motor. Removing the lcd display code solves things but I really need to know the real-time display of steps made by the motor. Any help is greatly appreciated. Thank you!
Logged

New Jersey
Offline Offline
Faraday Member
**
Karma: 65
Posts: 3638
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Is it any smoother if you just print the value of the changing variable? i.e. Don't send "Marking Depth" and "Microns"  more than once- move them to setup.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 25
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

yes, it is smoother if i just print the value. If I move Marking depth and Microns to setup I cannot display other messages on the lcd...
Logged

New Jersey
Offline Offline
Faraday Member
**
Karma: 65
Posts: 3638
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Is it possible to add some logic to your sketch so that you only change the labels when you have to? I imagine you would still get stepper stutter at change over though. Easier to tell if you could post your code.
Logged

New Hampshire
Offline Offline
God Member
*****
Karma: 17
Posts: 781
There are 10 kinds of people, those who know binary, and those who don't.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

but I really need to know the real-time display of steps made by the motor.

Hardly anything ever really needs to be displayed real-time.  Human perception isn't even capable of detecting display refreshes faster than about 30-60hz (not to mention affordable LCD character displays aren't capable of refreshing faster than that), and the human brain isn't capable of acknowledging data updates faster than about 1-5hz.  Keep track of the step count, and update ONLY the value on your display every 200-500msec and you'll have what you really need.
Logged


0
Offline Offline
Newbie
*
Karma: 0
Posts: 25
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

any pointers on how I should do this?  smiley-red

Thank you all
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 602
Posts: 33371
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Keep track of the step count, and update ONLY the value on your display every 200-500msec
The problem is that even this will cause a stutter in the motor. This is because the timing between the steps is just controlled in the loop, if the code does anything else (like write to the display) then the timing of the next step is longer.

The only way round this is to use a timer to generate an interrupt every time the stepper needs to step. Then the main loop can happily look at variables and print them out. This is because you will not see the stutter introduced by the motor grabbing the CPU time on the display.

Look up interrupts and how to initiate them in the playground.
Logged

'round the world...
Offline Offline
Faraday Member
**
Karma: 42
Posts: 3223
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

yes, it is smoother if i just print the value. If I move Marking depth and Microns to setup I cannot display other messages on the lcd...

If I remember correctly... you can write the "Marking Depth" and "Microns" on the setup function and then only write the step values like you did before.

When you write a different message on the LCD, you then need to re-write the "Marking Depth" and "Microns" in the LCD. You can create a bool variable that, if set, will write those messages in the LCD. Got it?

Code:
boolean refresh;
unsigned int time_to_refresh;

setup()  {
write_LCD ("Marking Depth" and "Microns");
refresh = 0;
time_to_refresh = 0;
}
loop() {
position_after("Marking Depth" and "Microns" );
write_LCD (marking depth);
write_LCD (microns);

if (something_happened)  {
write_LCD ("hey... something's happened!!!!");
time_to_refresh = 50000;
refresh =1;
}

if (refresh ==1 && time_to_refresh > 0)  {
time_to_refresh--;
 }
else  {
write_LCD ("Marking Depth" and "Microns");
refresh = 0;
time_to_refresh = 0;
}
}

I know that the code is not perfect... but it's something like this you'd need to do. :\ Or get a function called set_LCD () that will write all the constant string in the LCD and call that when you clear the message. I can give you a few more pointers on this, but I'd need to know what the system is doing and what are the inputs and outputs.
Logged

Eu não sou o teu criado. Se respondo no fórum é para ajudar todos mediante a minha disponibilidade e disposição. Responder por mensagem pessoal iria contra o propósito do fórum e por isso evito-o.
Se realmente pretendes que eu te ajude por mensagem pessoal, então podemos chegar a um acordo e contrato onde me pagas pela ajuda que eu fornecer e poderás então definir os termos de confidencialidade do meu serviço. De forma contrária toda e qualquer ajuda que eu der tem de ser visível a todos os participantes do fórum (será boa ideia, veres o significado da palavra fórum).
Nota também que eu não me responsabilizo por parvoíces escritas neste espaço pelo que se vais seguir algo dito por mim, entende que o farás por tua conta e risco.

Dito isto, mensagens pessoais só se forem pessoais, ou seja, se já interagimos de alguma forma no passado ou se me pretendes convidar para uma churrascada com cerveja (paga por ti, obviamente).

Pages: [1]   Go Up
Jump to: