Notifications
Clear all

Introduce myself and my stepping motor project (with questions)

41 Posts
5 Users
12 Likes
2,288 Views
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2531
 

@jker 

But the driver has to turn the pin HIGH, then wait and then turn it LOW again. Depending on the speed set, that may not be negligible. Especially if they're using a library for the stepper.

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2531
 

@jker 

But the driver has to turn the pin HIGH, then wait and then turn it LOW again. Depending on the speed set, that may not be negligible. Especially if they're using a library for the stepper.

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
 GNK
(@gnk)
Member
Joined: 3 years ago
Posts: 12
Topic starter  

@jker @will

This is probably getting beyond what I and my student are capable of. Would it be appropriate to suggest that I could send the code for either or both of you to inspect? If it were something that you would want to look at more formally, we could make a formal agreement with compensation. The problem is that you don't have the hardware of course.....


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2531
 

@gnk @jker

There have been several alternatives presented, all of which have the potential to save time. But it seems to me that you are struggling too hard and need to consider alternatives to the Arduino.

In my judgement, storing the results to the SD card as soon as you read the data is the biggest obstacle to be overcome. Pin pounding can recover a small amount of time but I don't think it will be enough.

So, since I think what you really need is enough more memory to store the raw values (step count and 16bit ints) as generated so that you can store them afterwards onto the SD card, there's no point in my looking at your code.

But, that's just my opinion based on the information presented so far.

Good luck with the project 🙂

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
jker
 jker
(@jker)
Member
Joined: 3 years ago
Posts: 82
 

My proof of concept code was simply trying to see if the SD card write was the bottleneck... but I can't say that I think it is at this point. Writing to flash _is_ slow, but apparently the arduino SD library uses an internal buffer to smooth this out.

What is probably happening is some bit of code that seems innocuous is causing serious timing problems.

  • Something like checking millis() too often (my code performance is cut in half if I call millis() in loop)
  • perhaps flushing or closing the file when we aren't done with it.
  • perhaps there's some delay or interference between the various serial modules (the i2c adc and the spi sd card interface)

If the issue is timing between the various modules, you're not really going to help anything by switching processors.

  • The ADC isn't going to go any faster
  • Neither is the SD card.
  • Neither communications protocol is going to change speed.
  • Unless you're REALLY moving that stepper motor quickly, you should be able to control it in a simple loop calculation like the AccelStepper library does.

"A resistor makes a lightbulb and a capacitor makes an explosion when connected wrong"
"There are two types of electrical engineers, those intentionally making antennas and those accidentally doing so."


   
frogandtoad reacted
ReplyQuote
 GNK
(@gnk)
Member
Joined: 3 years ago
Posts: 12
Topic starter  

@jker @will

Thanks to you both for taking the time to offer your suggestions. We'll keep working on it and followup here. 


   
frogandtoad reacted
ReplyQuote
frogandtoad
(@frogandtoad)
Member
Joined: 5 years ago
Posts: 1458
 
Posted by: @gnk

@jker @will

Thanks to you both for taking the time to offer your suggestions. We'll keep working on it and followup here. 

FYI -  you can also use the "new" C++ keyword to write to the heap - This may or may not be beneficial, but worth a look, as it can offer some more memory to play with.

Also, have you you considered the Arduino DUE microprocessor?

It is way, way faster, and offers 12 bit ADAC resolution... works on 3.3 volts instead of 5, but I don't see that as a problem.

Anyway, something to think about.

Cheers.


   
ReplyQuote
 GNK
(@gnk)
Member
Joined: 3 years ago
Posts: 12
Topic starter  

@frogandtoad 

Thanks for this suggestion. Having an amped-up Arduino with more memory and a built-in ADC might be the easiest solution. I've ordered one now!

Greg


   
frogandtoad reacted
ReplyQuote
jker
 jker
(@jker)
Member
Joined: 3 years ago
Posts: 82
 
Posted by: @frogandtoad

FYI -  you can also use the "new" C++ keyword to write to the heap - This may or may not be beneficial, but worth a look, as it can offer some more memory to play with.

Note that using heap allocation doesn't get you any extra memory, it just provides a way of only using the memory you actually need.

On the arduino, statically allocated memory is allocated in a block of sram (as this is known at compile time), and then the heap and stack grow at each other in opposite directions in the remaining SRAM out of the same 2k of sram. This is much, much easier to understand with a picture. https://learn.adafruit.com/memories-of-an-arduino/arduino-memories

"A resistor makes a lightbulb and a capacitor makes an explosion when connected wrong"
"There are two types of electrical engineers, those intentionally making antennas and those accidentally doing so."


   
frogandtoad reacted
ReplyQuote
jker
 jker
(@jker)
Member
Joined: 3 years ago
Posts: 82
 
Posted by: @gnk

@jker @will

This is probably getting beyond what I and my student are capable of. Would it be appropriate to suggest that I could send the code for either or both of you to inspect? If it were something that you would want to look at more formally, we could make a formal agreement with compensation. The problem is that you don't have the hardware of course.....

Sorry, I missed this earlier.  I, at least, cannot do this easily.

Big picture, the most important thing is probably to figure out what your target is. It is a little odd that after a few pages of talking about this, I still don't know.

1 kHz as a target, mentioned in passing I think, gives you 2.5 revs on a standard 0.9 degree non-microstepped stepper motor. Is 2.5revs/second / 150 rpm what you need as your top speed? Or is the speed "as fast as possible"?

I mainly ask because the ADC you've specified has a limit of 800Hz, which means that perhaps that should be your target since you wanted them sync'd?

"A resistor makes a lightbulb and a capacitor makes an explosion when connected wrong"
"There are two types of electrical engineers, those intentionally making antennas and those accidentally doing so."


   
ReplyQuote
frogandtoad
(@frogandtoad)
Member
Joined: 5 years ago
Posts: 1458
 

@jker 

Posted by: @frogandtoad
Posted by: @frogandtoad

FYI -  you can also use the "new" C++ keyword to write to the heap - This may or may not be beneficial, but worth a look, as it can offer some more memory to play with.

Note that using heap allocation doesn't get you any extra memory, it just provides a way of only using the memory you actually need.

100% correct, and thanks for the correction jker... I really meant to say that more memory options were available to you, in the way that you utilise memory, IOW... there is some flexibility in memory management available to you, should you choose to use it.

Cheers!


   
ReplyQuote
Page 3 / 3