Hello dear community,
I need to make some Open-loop controller for a mechanical system and I am wondering if it is feasible with the arduinos.
Background:
The mechanical system is making a peridodic movement at about 100Hz. I can measure this movement with a sensor which outputs an analogue signal. I will measure with 10kHz in order to get 100 measurements per cycle. The controller must now switch on and off a constant analogue signal to an actuator once every cycle. The switching happens at a specified voltage of the sensor.
The requirements are thus:
- the time between the physical event (mechanical system reaching a certain state) and the switching of the analogue output should not be larger than say 0.1 millisecond (although 1 millisecond would be acceptable).
Arduino for this project:
- any that meets those requirements. I thought about the Arduino Due because it has already a built-in DAC.
Is this possible? How can I estimate or calculate this time with the datasheets? I have no clue.
Any help appreciated!
I will measure with 10kHz in order to get 100 measurements per cycle.
How are you planning to get 10000 equally spaced samples every second? Or even for 1/100th of second?
the time between the physical event (mechanical system reaching a certain state)
What state is that, and how does that relate to the analog values you plan to read?
I thought about the Arduino Due because it has already a built-in DAC.
Why do you need a built-in DAC to turn some external analog signal generator on or off? If there is not an external signal generator, you need to explain what "switch on and off a constant analogue signal" means.
Thank you for your comments.
How are you planning to get 10000 equally spaced samples every second? Or even for 1/100th of second?
Well, I thought this could be easily done with some loop and some analogRead function?
What state is that, and how does that relate to the analog values you plan to read?
The analogue values I read are coming from an optical sensor which measures a certain movement. When the movement reaches a certain fixed but arbitrary point, I can see this through the sensor output.
Why do you need a built-in DAC to turn some external analog signal generator on or off? If there is not an external signal generator, you need to explain what "switch on and off a constant analogue signal" means.
I didn't speak about an analogue signal generator. In simple words, I want to be able to quickly change the operation voltage of the actuator. This should be done through the analogue output of the Arduino (and some amplifier).
As far as I can undertand you requirements, it seems really easy to achieve with a DUE:
Select ADC sampling with a 10 KHz frequency, program a PDC DMA to log 100 samplings (uint16_t values) into a buffer. Each time the PDC buffer is full (with 100 samplings), an interrupt is triggered.
Inside this interrupt:
- Output thru one of the DACs a value,
- Trigger the start of a new packet of 100 samplings,
- And in the mean time, e.g. average the 100 previous samplings to decide which will be the next value to output thru the DAC.
Note that the DUE DACs output analog signals are between 1/6 * 3.3V and 5/6 * 3.3V. For full range DACs, some additional hardware is needed.
Thank you for your suggestions!
I do not know at the moment what this DMA is exactly (or why I would need it and not just use the DAC directly). Do you use this for extra speed? It sounds like that.
You gave me also some ideas how to implement my controller, thanks for that!
But anyway: what about the processing speed? Will the time delay between physical movement and DAC output stay under 0.1 millisecond. You didn't speak about that. I simply do not know where to look up such an information from the datasheets.
kradant:
I do not know at the moment what this DMA is exactly
A DMA (Direct Memory Address) runs in parallel of the CPU, therefore the uc will sample while you can do some math (with the CPU) from the previous 100 samplings.
kradant:
But anyway: what about the processing speed?
From the moment you write a 12-bit value to output in the DAC register, the uc needs less than 300 ns to actually output the corresponding analog value at the DAC pin, so waaaaay less than 100000 ns
But anyway: what about the processing speed? Will the time delay between physical movement and DAC output stay under 0.1 millisecond. You didn't speak about that. I simply do not know where to look up such an information from the datasheets.
It's not real easy... You'd need an analysis of the machine code (or [u]assembly code[/u]). The chip is running compiled machine code, it's not directly running C/C++. You can't know the execution time until after the source code (C++) is compiled.
Or you can write the program (or part of the program) in assembly.
If you look in the datasheet for the chip it tells you the number of clock cycles needed for each machine code instruction. I don't know exactly how to get the assembly language code but it should be possible.
0.1ms is probably possible with the Due, but not with the "regular Arduino". It depends on how mush "stuff" you are doing between reading & writing.
BTW - You probably don't need 100 samples per cycle. [u]Sampling Theory[/u] says you can get away with a little more than 2 samples-per-cycle. For example audio CDs have a sample rate of 44.1kHz to give you audio above 20kHz. But, that assumes "continuous" waveform so depending on your requirements you may not be able to "push it" that far. (The 100MHz oscilloscope on my work bench at work samples at 1100MHz.)
Thank you! This gets me back on track. With your informations I found out also another discussions with the same topic (for example how to calculate clock cycle of an instruction - Programming Questions - Arduino Forum).