Notifications
Clear all

Introduce myself and my stepping motor project (with questions)

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

@gnk @jker

So you're getting a 16 bit value ... isn't that already an int ?

What am I missing here ?

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


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

@gnk @jker

I don't know how well this applies to your situation, but check out using PROGMEM

https://www.arduino.cc/reference/en/language/variables/utilities/progmem/

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


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

@will 

Right now, we are reading the load cell signal with a 16-bit ADC (ADS1115) which uses I2C. We wanted better resolution than the inherent 10-bit approach. Thoughts? 

10bit to 16bit doesn't matter in terms of data storage unless you're being very fancy. In both cases it's 2 bytes.

2000 bytes / 2 bytes per sample is 1000 samples, assuming you have _no_ other variables in your program. (an idealization at the level of "assume a cow is a sphere and sits on a frictionless surface")

At maximum speed for an ADS1115, that's just over 1 second of samples... but you probably can get away with using timer interrupts for your ADS control to slow this down.

Do you actually need the full log per sample? Why not just log percentage setpoints (10%, 20%, etc...)

"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
jker
 jker
(@jker)
Member
Joined: 3 years ago
Posts: 82
 
Posted by: @will

@gnk @jker

I don't know how well this applies to your situation, but check out using PROGMEM

https://www.arduino.cc/reference/en/language/variables/utilities/progmem/

Two reasons I would hesitate here:

PROGMEM is flash, and therefore can have some performance complications in getting things into and out of it.

PROGMEM is flash, therefore writings something like a log file to it is going to induce flash wear. This is less of a concern with an SD card that can be easily ejected and replaced than the on-board flash.

"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
jker
 jker
(@jker)
Member
Joined: 3 years ago
Posts: 82
 

My general approach to figuring out this issue:

  1. Confirm that the stepper control generally works correctly without the logging component
    1. If not, figure out if the issue is being caused by the I2C controls.
  2. Re-add the logging in the sense of dumping the data to serial. This is _fairly_ fast on arduino, and allows us to verify that the log prep and processing is not the issue.
  3. Determine if we can minimize the data we need to log
    1. Determine the actual data logging need. 
    2. Reduce the sheer volume of data to something we can cache
    3. Compress using a delta (in this case, that only doubles the available sram storage)
  4. Determine if we can use an asynchronous write operation for the flash write. This depends a bit on the SD card interface we have.

"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
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2504
 
Posted by: @jker
Posted by: @will

@gnk @jker

I don't know how well this applies to your situation, but check out using PROGMEM

https://www.arduino.cc/reference/en/language/variables/utilities/progmem/

Two reasons I would hesitate here:

PROGMEM is flash, and therefore can have some performance complications in getting things into and out of it.

PROGMEM is flash, therefore writings something like a log file to it is going to induce flash wear. This is less of a concern with an SD card that can be easily ejected and replaced than the on-board flash.

Was considering using flash to store prompts and reporting strings in order to free up space for storing data.

Any idea whether the onboard (or external) EEProm would be faster than an SD card ?

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


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

@jker 

The reason to pick up load cell data for each motor step is we need to graph load cell output as a function of steps. We need a good sample rate (1kHz) and decent analog sample resolution (hence 16 bit) as the resulting curve can change quickly and we don't want to miss those nuances in the output. 

So to summarize the ideas of how we collect this data, it looks like we will run out of memory if we use an array to collect the number of steps and load cell output values for more than a second (assuming no other variables, cows etc). PROGMEM as an alternative was suggested to have its own problems. SD card is too slow.

What's the solution here? 


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2504
 
Posted by: @gnk

@jker 

The reason to pick up load cell data for each motor step is we need to graph load cell output as a function of steps. We need a good sample rate (1kHz) and decent analog sample resolution (hence 16 bit) as the resulting curve can change quickly and we don't want to miss those nuances in the output. 

So to summarize the ideas of how we collect this data, it looks like we will run out of memory if we use an array to collect the number of steps and load cell output values for more than a second (assuming no other variables, cows etc). PROGMEM as an alternative was suggested to have its own problems. SD card is too slow.

What's the solution here? 

Since you seem to be scraping the metal off the Arduino, how about switching over to a Raspberry Pi PICO ?

You can still use the Arduino IDE but you get massively more flash, SRAM and processor speed.

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


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

@will 

Might have to give that a try. Will report back. 


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

@gnk @jker

The XIAO is also a good alternative, Bi''ls done a good video for it

https://forum.dronebotworkshop.com/2020/seeeduino-xiao-32-bit-arduino-compatible-microcontroller/#post-14985

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


   
ReplyQuote
byron
(@byron)
No Title
Joined: 5 years ago
Posts: 1112
 
Posted by: @will

how about switching over to a Raspberry Pi PICO ?

You can still use the Arduino IDE but you get massively more flash, SRAM and processor speed.

Another alternative to @wills suggestion is to consider using a Teensy 4.1 if speed and flash are important.  Its a beast and can still be used with, admittedly a Teensy modified, Arduino environment.


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

Yeah... I was thinking about alternatives... but I'm honestly not sure it's needed. I took a break to pull out my SPI SD card module and do some testing.,

The following code:

void loop() {
  if (running) {
    int x = analogRead(A0);
    PORTD ^= B10000000;
    Serial.println(x);
    file.println(x);
    if (!digitalRead(TRIGGER)) {
      running = false;
      file.close();
    }
  }
}

runs at about 0.3ms/loop (measured on the scope). This is about 3.2kHz in terms of sampling speed, quite a bit above what seems to be needed. This is running with a simple 2kHz TCCR0 timer running in the background.

Admittedly it doesn't give much headroom, but this seems adequate.

"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
jker
 jker
(@jker)
Member
Joined: 3 years ago
Posts: 82
 

To me, my bit of sample code here gives the outline of what can be done in the loop. But we still don't actually know what frequency we need to update the stepper at.

This is sortof what I was "simulating" with the TCNT0 timer, but I still don't know what the target is.

"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
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2504
 

@jker @gnk

Your test sketch doesn't appear to be allowing for the time for the stepper motor to step.

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


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

Your test sketch doesn't appear to be allowing for the time for the stepper motor to step.

Well... keep in mind that we would probably step using a timed interrupt routine. And that doesn't seem to change the timing at least at the level I tried it. (2kHz on timer0)

I also just tried fiddling around with analogWrite on pin 3 at the same time... looks like there's a bit of variation, but not too bad.

"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
Page 2 / 3