Processing ADC conversion result: DMA vs Processor Registers Unicorn Meta Zoo #1: Why another...
Why doesn't the university give past final exams' answers?
Simulate round-robin tournament draw
Protagonist's race is hidden - should I reveal it?
How do I deal with an erroneously large refund?
Can gravitational waves pass through a black hole?
What to do with someone that cheated their way though university and a PhD program?
Are these square matrices always diagonalisable?
using NDEigensystem to solve the Mathieu equation
How did Elite on the NES work?
What is the numbering system used for the DSN dishes?
Does a Draconic Bloodline sorcerer's doubled proficiency bonus for Charisma checks against dragons apply to all dragon types or only the chosen one?
When speaking, how do you change your mind mid-sentence?
Retract an already submitted Recommendation Letter (written for an undergrad student)
What is a 'Key' in computer science?
Why isPrototypeOf() returns false?
Did war bonds have better investment alternatives during WWII?
false 'Security alert' from Google - every login generates mails from 'no-reply@accounts.google.com'
Why did Israel vote against lifting the American embargo on Cuba?
France's Public Holidays' Puzzle
Married in secret, can marital status in passport be changed at a later date?
Will I be more secure with my own router behind my ISP's router?
Mechanism of the formation of peracetic acid
Is it OK if I do not take the receipt in Germany?
Stretch a Tikz tree
Processing ADC conversion result: DMA vs Processor Registers
Unicorn Meta Zoo #1: Why another podcast?
Announcing the arrival of Valued Associate #679: Cesar ManaraSTM32F103 ADC NoiseQuestion about the registers of an ADCstm32 f411re ADC + DMAWhat's the point of DMA in embedded CPU's?Input/output from unsynchronized ADC/DACSeveral questions about the ADC LTC2323 function, I'm new in electronicsWhy not always use DMA in favor of interrupts with UART on STM32?How to dynamically adjust a timer with STM32STMF4 ADC conversion seems slowBig code in interrupt freezes main function
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
$begingroup$
I have a periodic ADC conversion (every 50 micro-seconds) and I use the result to do some further calculations and update the PWM load registers. The ADC is triggered by the up-down counter of hardware PWM and has to be done exactly at that time. I am using a Teensy 3.2 (ARM M4) and although it's a beast, I have to be as fast as possible with the ADC to be able to squeeze in the rest of the calculations before the next duty cycle starts.
The general idea to operate faster seems like using DMA which transfers the conversion results directly to system memory without involving CPU, which looks like
ADC_result -> DMA -> SRAM,
But after that I have to fetch the result back from the SRAM to process it, which looks like:
ADC_result -> DMA -> SRAM -> CPU -> finally getting processed.
Of course, not involving the DMA is way slower:
ADC_result -> CPU -> SRAM -> CPU -> finally getting processed.
My question is, since I have to put the conversion result into CPU to be processed anyhow, can't I just store it directly in processor registers without involving DMA or SRAM at all and process is right away?
ADC_result -> CPU -> finally getting processed.
There are a couple of points I would like to make to further clarify the nature of my issue and test any gaps in my understanding.
First, from what I have understood, DMA is mainly used when there is real logging to be done and we would to use the CPU in parallel, especially if the data providing peripheral is considerably faster/slower than CPU. This is not my case, since all the following calculation are dependent on the ADC conversion result and I have very little data being sent every 50 micro-seconds rather than huge chunks.
Second, there is no guarantee that I will be able to use processor registers freely, since they are subjugated to compiler optimization and might be totally ignored (using the register keyword in C).
I would love to hear any feedback on the matter, especially if my understanding is somewhat flawed or plain wrong.
adc register dma data-acquisition
$endgroup$
add a comment |
$begingroup$
I have a periodic ADC conversion (every 50 micro-seconds) and I use the result to do some further calculations and update the PWM load registers. The ADC is triggered by the up-down counter of hardware PWM and has to be done exactly at that time. I am using a Teensy 3.2 (ARM M4) and although it's a beast, I have to be as fast as possible with the ADC to be able to squeeze in the rest of the calculations before the next duty cycle starts.
The general idea to operate faster seems like using DMA which transfers the conversion results directly to system memory without involving CPU, which looks like
ADC_result -> DMA -> SRAM,
But after that I have to fetch the result back from the SRAM to process it, which looks like:
ADC_result -> DMA -> SRAM -> CPU -> finally getting processed.
Of course, not involving the DMA is way slower:
ADC_result -> CPU -> SRAM -> CPU -> finally getting processed.
My question is, since I have to put the conversion result into CPU to be processed anyhow, can't I just store it directly in processor registers without involving DMA or SRAM at all and process is right away?
ADC_result -> CPU -> finally getting processed.
There are a couple of points I would like to make to further clarify the nature of my issue and test any gaps in my understanding.
First, from what I have understood, DMA is mainly used when there is real logging to be done and we would to use the CPU in parallel, especially if the data providing peripheral is considerably faster/slower than CPU. This is not my case, since all the following calculation are dependent on the ADC conversion result and I have very little data being sent every 50 micro-seconds rather than huge chunks.
Second, there is no guarantee that I will be able to use processor registers freely, since they are subjugated to compiler optimization and might be totally ignored (using the register keyword in C).
I would love to hear any feedback on the matter, especially if my understanding is somewhat flawed or plain wrong.
adc register dma data-acquisition
$endgroup$
$begingroup$
You write in a comment that you are "implementing a motor control algorithm." In almost all such circumstances I've experienced, this required very carefully designed sample-to-output timing. I will tend to keep the sample-to-sample measurement cycle-exact from one to the next (this can be achieved with DMA or, often enough, without DMA) and also keep the time from sample-to-output as close to cycle-exact as I can achieve. This almost always means "some assembly" mixed with C. If not, the closed loop control isn't competitive enough and will fail to my betters in the marketplace, eventually.
$endgroup$
– jonk
11 hours ago
$begingroup$
I should have added this: I also keep the sample-to-output as short as possible. Short is even more important than consistent timing, though both are important. A control algorithm can accept some inconsistency in the delay, if the delay is very short. But long delays -- and especially long delays with variability to them -- are certain death. Keep things as tight and close as possible and keep the variability as minimal as you can achieve. The rest will just follow, if you can do that.
$endgroup$
– jonk
11 hours ago
$begingroup$
What is the dominant pole in the motor?
$endgroup$
– copper.hat
3 hours ago
add a comment |
$begingroup$
I have a periodic ADC conversion (every 50 micro-seconds) and I use the result to do some further calculations and update the PWM load registers. The ADC is triggered by the up-down counter of hardware PWM and has to be done exactly at that time. I am using a Teensy 3.2 (ARM M4) and although it's a beast, I have to be as fast as possible with the ADC to be able to squeeze in the rest of the calculations before the next duty cycle starts.
The general idea to operate faster seems like using DMA which transfers the conversion results directly to system memory without involving CPU, which looks like
ADC_result -> DMA -> SRAM,
But after that I have to fetch the result back from the SRAM to process it, which looks like:
ADC_result -> DMA -> SRAM -> CPU -> finally getting processed.
Of course, not involving the DMA is way slower:
ADC_result -> CPU -> SRAM -> CPU -> finally getting processed.
My question is, since I have to put the conversion result into CPU to be processed anyhow, can't I just store it directly in processor registers without involving DMA or SRAM at all and process is right away?
ADC_result -> CPU -> finally getting processed.
There are a couple of points I would like to make to further clarify the nature of my issue and test any gaps in my understanding.
First, from what I have understood, DMA is mainly used when there is real logging to be done and we would to use the CPU in parallel, especially if the data providing peripheral is considerably faster/slower than CPU. This is not my case, since all the following calculation are dependent on the ADC conversion result and I have very little data being sent every 50 micro-seconds rather than huge chunks.
Second, there is no guarantee that I will be able to use processor registers freely, since they are subjugated to compiler optimization and might be totally ignored (using the register keyword in C).
I would love to hear any feedback on the matter, especially if my understanding is somewhat flawed or plain wrong.
adc register dma data-acquisition
$endgroup$
I have a periodic ADC conversion (every 50 micro-seconds) and I use the result to do some further calculations and update the PWM load registers. The ADC is triggered by the up-down counter of hardware PWM and has to be done exactly at that time. I am using a Teensy 3.2 (ARM M4) and although it's a beast, I have to be as fast as possible with the ADC to be able to squeeze in the rest of the calculations before the next duty cycle starts.
The general idea to operate faster seems like using DMA which transfers the conversion results directly to system memory without involving CPU, which looks like
ADC_result -> DMA -> SRAM,
But after that I have to fetch the result back from the SRAM to process it, which looks like:
ADC_result -> DMA -> SRAM -> CPU -> finally getting processed.
Of course, not involving the DMA is way slower:
ADC_result -> CPU -> SRAM -> CPU -> finally getting processed.
My question is, since I have to put the conversion result into CPU to be processed anyhow, can't I just store it directly in processor registers without involving DMA or SRAM at all and process is right away?
ADC_result -> CPU -> finally getting processed.
There are a couple of points I would like to make to further clarify the nature of my issue and test any gaps in my understanding.
First, from what I have understood, DMA is mainly used when there is real logging to be done and we would to use the CPU in parallel, especially if the data providing peripheral is considerably faster/slower than CPU. This is not my case, since all the following calculation are dependent on the ADC conversion result and I have very little data being sent every 50 micro-seconds rather than huge chunks.
Second, there is no guarantee that I will be able to use processor registers freely, since they are subjugated to compiler optimization and might be totally ignored (using the register keyword in C).
I would love to hear any feedback on the matter, especially if my understanding is somewhat flawed or plain wrong.
adc register dma data-acquisition
adc register dma data-acquisition
edited 13 hours ago
JYelton
16.5k2891194
16.5k2891194
asked 14 hours ago
Firat.Berk.CakarFirat.Berk.Cakar
445
445
$begingroup$
You write in a comment that you are "implementing a motor control algorithm." In almost all such circumstances I've experienced, this required very carefully designed sample-to-output timing. I will tend to keep the sample-to-sample measurement cycle-exact from one to the next (this can be achieved with DMA or, often enough, without DMA) and also keep the time from sample-to-output as close to cycle-exact as I can achieve. This almost always means "some assembly" mixed with C. If not, the closed loop control isn't competitive enough and will fail to my betters in the marketplace, eventually.
$endgroup$
– jonk
11 hours ago
$begingroup$
I should have added this: I also keep the sample-to-output as short as possible. Short is even more important than consistent timing, though both are important. A control algorithm can accept some inconsistency in the delay, if the delay is very short. But long delays -- and especially long delays with variability to them -- are certain death. Keep things as tight and close as possible and keep the variability as minimal as you can achieve. The rest will just follow, if you can do that.
$endgroup$
– jonk
11 hours ago
$begingroup$
What is the dominant pole in the motor?
$endgroup$
– copper.hat
3 hours ago
add a comment |
$begingroup$
You write in a comment that you are "implementing a motor control algorithm." In almost all such circumstances I've experienced, this required very carefully designed sample-to-output timing. I will tend to keep the sample-to-sample measurement cycle-exact from one to the next (this can be achieved with DMA or, often enough, without DMA) and also keep the time from sample-to-output as close to cycle-exact as I can achieve. This almost always means "some assembly" mixed with C. If not, the closed loop control isn't competitive enough and will fail to my betters in the marketplace, eventually.
$endgroup$
– jonk
11 hours ago
$begingroup$
I should have added this: I also keep the sample-to-output as short as possible. Short is even more important than consistent timing, though both are important. A control algorithm can accept some inconsistency in the delay, if the delay is very short. But long delays -- and especially long delays with variability to them -- are certain death. Keep things as tight and close as possible and keep the variability as minimal as you can achieve. The rest will just follow, if you can do that.
$endgroup$
– jonk
11 hours ago
$begingroup$
What is the dominant pole in the motor?
$endgroup$
– copper.hat
3 hours ago
$begingroup$
You write in a comment that you are "implementing a motor control algorithm." In almost all such circumstances I've experienced, this required very carefully designed sample-to-output timing. I will tend to keep the sample-to-sample measurement cycle-exact from one to the next (this can be achieved with DMA or, often enough, without DMA) and also keep the time from sample-to-output as close to cycle-exact as I can achieve. This almost always means "some assembly" mixed with C. If not, the closed loop control isn't competitive enough and will fail to my betters in the marketplace, eventually.
$endgroup$
– jonk
11 hours ago
$begingroup$
You write in a comment that you are "implementing a motor control algorithm." In almost all such circumstances I've experienced, this required very carefully designed sample-to-output timing. I will tend to keep the sample-to-sample measurement cycle-exact from one to the next (this can be achieved with DMA or, often enough, without DMA) and also keep the time from sample-to-output as close to cycle-exact as I can achieve. This almost always means "some assembly" mixed with C. If not, the closed loop control isn't competitive enough and will fail to my betters in the marketplace, eventually.
$endgroup$
– jonk
11 hours ago
$begingroup$
I should have added this: I also keep the sample-to-output as short as possible. Short is even more important than consistent timing, though both are important. A control algorithm can accept some inconsistency in the delay, if the delay is very short. But long delays -- and especially long delays with variability to them -- are certain death. Keep things as tight and close as possible and keep the variability as minimal as you can achieve. The rest will just follow, if you can do that.
$endgroup$
– jonk
11 hours ago
$begingroup$
I should have added this: I also keep the sample-to-output as short as possible. Short is even more important than consistent timing, though both are important. A control algorithm can accept some inconsistency in the delay, if the delay is very short. But long delays -- and especially long delays with variability to them -- are certain death. Keep things as tight and close as possible and keep the variability as minimal as you can achieve. The rest will just follow, if you can do that.
$endgroup$
– jonk
11 hours ago
$begingroup$
What is the dominant pole in the motor?
$endgroup$
– copper.hat
3 hours ago
$begingroup$
What is the dominant pole in the motor?
$endgroup$
– copper.hat
3 hours ago
add a comment |
4 Answers
4
active
oldest
votes
$begingroup$
If you just write a function that reads the ADC result into a variable, does some math on it, and then writes the result to PWM, and if you use a decent compiler with optimization turned up, then the critical data will probably end up in a register whether you want it to or not. That's really not that much different from setting up DMA just so that you can fetch one memory location and do the same thing.
Where I would use DMA for this sort of thing is if I were going to do something like fetch multiple ADC samples per cycle of the controller (which I often do) -- the DMA saves a lot vs. the overhead of an ISR to collect the data from an ADC.
$endgroup$
$begingroup$
thanks for the insight, but i am implementing a motor control algorithm which requires sampling at very specific times in order to measure the current when all 3 high side switches are on. So i really cant use a function and poll the ADC.
$endgroup$
– Firat.Berk.Cakar
14 hours ago
1
$begingroup$
@Firat.Berk.Cakar I would think that many things about a motor control system would be so low-pass that none of this would be necessary
$endgroup$
– Scott Seidman
11 hours ago
1
$begingroup$
I didn't say to use a function to poll the ADC. I just said that you can read the ADC register, deal with it, and write to PWM. You should set up your ADC to fire off of a timer, undoubtedly.
$endgroup$
– TimWescott
11 hours ago
$begingroup$
@ScottSeidman, if the OP is controlling the motor current then he wants cycle-by-cycle, or near cycle-by-cycle control (the last one I did I got away with iterating the control loop every 2 PWM cycles, but I don't claim to be very proud of that). For that you want to be able to have low and predictable delay.
$endgroup$
– TimWescott
6 hours ago
add a comment |
$begingroup$
My question is, since i have to put the conversion result into CPU to be processed anyhow, cant i just store it directly in processor registers without involving DMA or SRAM at all and process is right away?
No, this is not possible in an Cortex-M4. Moreover, you would not want this to be possible. To make it clear why: If you write your program in "not assembly", then you're going to use a compiler. Compilers generally abide by the ARM ABI which will let them use registers for data processing. What you are suggesting will cause both the compiler and the ADC to use the same location for different purposes at the same time. Your program will behave badly. You will have no way of telling a compiler that a certain register is off limits.
Of course, not involving the DMA is way slower:
ADC_result -> CPU -> SRAM -> CPU -> finally getting processed.
This isn't quite correct or incorrect. It's application specific. An interrupt can load the ADC result from the ADC data register directly to a CPU register if the function only uses that data locally and is "short". it's possible that data may never be stored in SRAM.
Now, whether you use DMA or an interrupt to transfer your data, interrupts are certainly easier to comprehend from a data flow point of view. Additionally, interrupts allow you to respond sample by sample, which may be necessary for your application. The down side is that it forces you to eat the overhead costs of entering and exiting an interrupt. That might matter for your application or not.
If you must do so much processing, that time is precious and you can not afford to operate on one sample at a time, DMA can get you out of that bind. DMA allows you to amortize the interrupt enter/exit costs over many samples (depending on your deadline). Additionally, there are some math algorithms which are much more efficient when performed over buffers rather than sample-by-sample as they arrive. Again, it will depend on your application.
Unless you spell out your applications requirements, it's impossible to tell which is the best approach.
$endgroup$
$begingroup$
Thanks for the long and comprehensive answer. First, i have to start the conversion at a very specific time (see my comment to other answer) and i also edited the first paragraph of my question. So in essence the conversion has to be started by the interrupt and now the question is rather to save this value with or without DMA. If i use the DMA, cant it lead to concurency issues ? For example when i start the conversation in the interrupt (with DMA) and move on directly to process it with in the interrupt, isnt it possible that the data isnt still there ?
$endgroup$
– Firat.Berk.Cakar
13 hours ago
$begingroup$
FWIW, if you really need exact timing, when you read the reference manual carefully, you'll see the ADC can be hardware triggered by the PDB which can be triggered by the Flex Timer. If you set your hardware up correctly, you will not need to interrupt to start the conversion.
$endgroup$
– pgvoorhees
10 hours ago
add a comment |
$begingroup$
There are three events that matter here:
- ADC start of conversion
- ADC end of conversion
- Deadline for updating PWM duty cycle
Your start of conversion should be triggered by hardware. It sounds like your PWM is already doing this.
You have to do the processing between the end of conversion and the deadline. The best way to do this is to have the end of conversion trigger a CPU interrupt. Your ADC should be able to do this. In the ISR, the CPU can do the processing and update the duty cycle.
If you're writing C code, you don't need to worry about SRAM and registers. Just read the ADC result into an integer variable. Here's some pseudo-code:
void ADC_EOC_ISR(void)
{
uint16_t adc_result = *ADC_RESULT_REG_ADDR;
uint16_t new_duty_cycle_value = compute_new_duty_cycle(adc_result);
*PWM_DUTY_CYCLE_REG = new_duty_cycle_value;
}
uint16_t compute_new_duty_cycle(uint16_t feedback)
{
... //Do processing here
}
The exact method for accessing the ADC result and PWM duty cycle registers depends on what MCU you're using and what header files/drivers have been provided.
$endgroup$
add a comment |
$begingroup$
Using DMA turns your hard realtime problem (process the sample before the next sample is overwritten) into a soft realtime problem (process samples faster than they accrue in the buffer and before the buffer gets full).
Hard realtime problems are annoying to handle, you usually need an interrupt source that is synchronous with the ADC (either a "conversion finished" interrupt from the ADC, or a periodic timer interrupt that also starts ADC conversion), which means that your CPU will spend quite a large amount of time entering and exiting interrupt handlers.
That can be a valid design if the ADC clock is slow enough that the interrupt handler finishes before the next interrupt arrives, and this is the highest priority interrupt (so other interrupt handlers do not stop data processing), but this is an engineering trade-off: the DMA based design is simpler, so unless delay and jitter need to be tightly controlled, it is likely the better choice.
$endgroup$
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
return StackExchange.using("schematics", function () {
StackExchange.schematics.init();
});
}, "cicuitlab");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "135"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2felectronics.stackexchange.com%2fquestions%2f434057%2fprocessing-adc-conversion-result-dma-vs-processor-registers%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
If you just write a function that reads the ADC result into a variable, does some math on it, and then writes the result to PWM, and if you use a decent compiler with optimization turned up, then the critical data will probably end up in a register whether you want it to or not. That's really not that much different from setting up DMA just so that you can fetch one memory location and do the same thing.
Where I would use DMA for this sort of thing is if I were going to do something like fetch multiple ADC samples per cycle of the controller (which I often do) -- the DMA saves a lot vs. the overhead of an ISR to collect the data from an ADC.
$endgroup$
$begingroup$
thanks for the insight, but i am implementing a motor control algorithm which requires sampling at very specific times in order to measure the current when all 3 high side switches are on. So i really cant use a function and poll the ADC.
$endgroup$
– Firat.Berk.Cakar
14 hours ago
1
$begingroup$
@Firat.Berk.Cakar I would think that many things about a motor control system would be so low-pass that none of this would be necessary
$endgroup$
– Scott Seidman
11 hours ago
1
$begingroup$
I didn't say to use a function to poll the ADC. I just said that you can read the ADC register, deal with it, and write to PWM. You should set up your ADC to fire off of a timer, undoubtedly.
$endgroup$
– TimWescott
11 hours ago
$begingroup$
@ScottSeidman, if the OP is controlling the motor current then he wants cycle-by-cycle, or near cycle-by-cycle control (the last one I did I got away with iterating the control loop every 2 PWM cycles, but I don't claim to be very proud of that). For that you want to be able to have low and predictable delay.
$endgroup$
– TimWescott
6 hours ago
add a comment |
$begingroup$
If you just write a function that reads the ADC result into a variable, does some math on it, and then writes the result to PWM, and if you use a decent compiler with optimization turned up, then the critical data will probably end up in a register whether you want it to or not. That's really not that much different from setting up DMA just so that you can fetch one memory location and do the same thing.
Where I would use DMA for this sort of thing is if I were going to do something like fetch multiple ADC samples per cycle of the controller (which I often do) -- the DMA saves a lot vs. the overhead of an ISR to collect the data from an ADC.
$endgroup$
$begingroup$
thanks for the insight, but i am implementing a motor control algorithm which requires sampling at very specific times in order to measure the current when all 3 high side switches are on. So i really cant use a function and poll the ADC.
$endgroup$
– Firat.Berk.Cakar
14 hours ago
1
$begingroup$
@Firat.Berk.Cakar I would think that many things about a motor control system would be so low-pass that none of this would be necessary
$endgroup$
– Scott Seidman
11 hours ago
1
$begingroup$
I didn't say to use a function to poll the ADC. I just said that you can read the ADC register, deal with it, and write to PWM. You should set up your ADC to fire off of a timer, undoubtedly.
$endgroup$
– TimWescott
11 hours ago
$begingroup$
@ScottSeidman, if the OP is controlling the motor current then he wants cycle-by-cycle, or near cycle-by-cycle control (the last one I did I got away with iterating the control loop every 2 PWM cycles, but I don't claim to be very proud of that). For that you want to be able to have low and predictable delay.
$endgroup$
– TimWescott
6 hours ago
add a comment |
$begingroup$
If you just write a function that reads the ADC result into a variable, does some math on it, and then writes the result to PWM, and if you use a decent compiler with optimization turned up, then the critical data will probably end up in a register whether you want it to or not. That's really not that much different from setting up DMA just so that you can fetch one memory location and do the same thing.
Where I would use DMA for this sort of thing is if I were going to do something like fetch multiple ADC samples per cycle of the controller (which I often do) -- the DMA saves a lot vs. the overhead of an ISR to collect the data from an ADC.
$endgroup$
If you just write a function that reads the ADC result into a variable, does some math on it, and then writes the result to PWM, and if you use a decent compiler with optimization turned up, then the critical data will probably end up in a register whether you want it to or not. That's really not that much different from setting up DMA just so that you can fetch one memory location and do the same thing.
Where I would use DMA for this sort of thing is if I were going to do something like fetch multiple ADC samples per cycle of the controller (which I often do) -- the DMA saves a lot vs. the overhead of an ISR to collect the data from an ADC.
answered 14 hours ago
TimWescottTimWescott
7,1391416
7,1391416
$begingroup$
thanks for the insight, but i am implementing a motor control algorithm which requires sampling at very specific times in order to measure the current when all 3 high side switches are on. So i really cant use a function and poll the ADC.
$endgroup$
– Firat.Berk.Cakar
14 hours ago
1
$begingroup$
@Firat.Berk.Cakar I would think that many things about a motor control system would be so low-pass that none of this would be necessary
$endgroup$
– Scott Seidman
11 hours ago
1
$begingroup$
I didn't say to use a function to poll the ADC. I just said that you can read the ADC register, deal with it, and write to PWM. You should set up your ADC to fire off of a timer, undoubtedly.
$endgroup$
– TimWescott
11 hours ago
$begingroup$
@ScottSeidman, if the OP is controlling the motor current then he wants cycle-by-cycle, or near cycle-by-cycle control (the last one I did I got away with iterating the control loop every 2 PWM cycles, but I don't claim to be very proud of that). For that you want to be able to have low and predictable delay.
$endgroup$
– TimWescott
6 hours ago
add a comment |
$begingroup$
thanks for the insight, but i am implementing a motor control algorithm which requires sampling at very specific times in order to measure the current when all 3 high side switches are on. So i really cant use a function and poll the ADC.
$endgroup$
– Firat.Berk.Cakar
14 hours ago
1
$begingroup$
@Firat.Berk.Cakar I would think that many things about a motor control system would be so low-pass that none of this would be necessary
$endgroup$
– Scott Seidman
11 hours ago
1
$begingroup$
I didn't say to use a function to poll the ADC. I just said that you can read the ADC register, deal with it, and write to PWM. You should set up your ADC to fire off of a timer, undoubtedly.
$endgroup$
– TimWescott
11 hours ago
$begingroup$
@ScottSeidman, if the OP is controlling the motor current then he wants cycle-by-cycle, or near cycle-by-cycle control (the last one I did I got away with iterating the control loop every 2 PWM cycles, but I don't claim to be very proud of that). For that you want to be able to have low and predictable delay.
$endgroup$
– TimWescott
6 hours ago
$begingroup$
thanks for the insight, but i am implementing a motor control algorithm which requires sampling at very specific times in order to measure the current when all 3 high side switches are on. So i really cant use a function and poll the ADC.
$endgroup$
– Firat.Berk.Cakar
14 hours ago
$begingroup$
thanks for the insight, but i am implementing a motor control algorithm which requires sampling at very specific times in order to measure the current when all 3 high side switches are on. So i really cant use a function and poll the ADC.
$endgroup$
– Firat.Berk.Cakar
14 hours ago
1
1
$begingroup$
@Firat.Berk.Cakar I would think that many things about a motor control system would be so low-pass that none of this would be necessary
$endgroup$
– Scott Seidman
11 hours ago
$begingroup$
@Firat.Berk.Cakar I would think that many things about a motor control system would be so low-pass that none of this would be necessary
$endgroup$
– Scott Seidman
11 hours ago
1
1
$begingroup$
I didn't say to use a function to poll the ADC. I just said that you can read the ADC register, deal with it, and write to PWM. You should set up your ADC to fire off of a timer, undoubtedly.
$endgroup$
– TimWescott
11 hours ago
$begingroup$
I didn't say to use a function to poll the ADC. I just said that you can read the ADC register, deal with it, and write to PWM. You should set up your ADC to fire off of a timer, undoubtedly.
$endgroup$
– TimWescott
11 hours ago
$begingroup$
@ScottSeidman, if the OP is controlling the motor current then he wants cycle-by-cycle, or near cycle-by-cycle control (the last one I did I got away with iterating the control loop every 2 PWM cycles, but I don't claim to be very proud of that). For that you want to be able to have low and predictable delay.
$endgroup$
– TimWescott
6 hours ago
$begingroup$
@ScottSeidman, if the OP is controlling the motor current then he wants cycle-by-cycle, or near cycle-by-cycle control (the last one I did I got away with iterating the control loop every 2 PWM cycles, but I don't claim to be very proud of that). For that you want to be able to have low and predictable delay.
$endgroup$
– TimWescott
6 hours ago
add a comment |
$begingroup$
My question is, since i have to put the conversion result into CPU to be processed anyhow, cant i just store it directly in processor registers without involving DMA or SRAM at all and process is right away?
No, this is not possible in an Cortex-M4. Moreover, you would not want this to be possible. To make it clear why: If you write your program in "not assembly", then you're going to use a compiler. Compilers generally abide by the ARM ABI which will let them use registers for data processing. What you are suggesting will cause both the compiler and the ADC to use the same location for different purposes at the same time. Your program will behave badly. You will have no way of telling a compiler that a certain register is off limits.
Of course, not involving the DMA is way slower:
ADC_result -> CPU -> SRAM -> CPU -> finally getting processed.
This isn't quite correct or incorrect. It's application specific. An interrupt can load the ADC result from the ADC data register directly to a CPU register if the function only uses that data locally and is "short". it's possible that data may never be stored in SRAM.
Now, whether you use DMA or an interrupt to transfer your data, interrupts are certainly easier to comprehend from a data flow point of view. Additionally, interrupts allow you to respond sample by sample, which may be necessary for your application. The down side is that it forces you to eat the overhead costs of entering and exiting an interrupt. That might matter for your application or not.
If you must do so much processing, that time is precious and you can not afford to operate on one sample at a time, DMA can get you out of that bind. DMA allows you to amortize the interrupt enter/exit costs over many samples (depending on your deadline). Additionally, there are some math algorithms which are much more efficient when performed over buffers rather than sample-by-sample as they arrive. Again, it will depend on your application.
Unless you spell out your applications requirements, it's impossible to tell which is the best approach.
$endgroup$
$begingroup$
Thanks for the long and comprehensive answer. First, i have to start the conversion at a very specific time (see my comment to other answer) and i also edited the first paragraph of my question. So in essence the conversion has to be started by the interrupt and now the question is rather to save this value with or without DMA. If i use the DMA, cant it lead to concurency issues ? For example when i start the conversation in the interrupt (with DMA) and move on directly to process it with in the interrupt, isnt it possible that the data isnt still there ?
$endgroup$
– Firat.Berk.Cakar
13 hours ago
$begingroup$
FWIW, if you really need exact timing, when you read the reference manual carefully, you'll see the ADC can be hardware triggered by the PDB which can be triggered by the Flex Timer. If you set your hardware up correctly, you will not need to interrupt to start the conversion.
$endgroup$
– pgvoorhees
10 hours ago
add a comment |
$begingroup$
My question is, since i have to put the conversion result into CPU to be processed anyhow, cant i just store it directly in processor registers without involving DMA or SRAM at all and process is right away?
No, this is not possible in an Cortex-M4. Moreover, you would not want this to be possible. To make it clear why: If you write your program in "not assembly", then you're going to use a compiler. Compilers generally abide by the ARM ABI which will let them use registers for data processing. What you are suggesting will cause both the compiler and the ADC to use the same location for different purposes at the same time. Your program will behave badly. You will have no way of telling a compiler that a certain register is off limits.
Of course, not involving the DMA is way slower:
ADC_result -> CPU -> SRAM -> CPU -> finally getting processed.
This isn't quite correct or incorrect. It's application specific. An interrupt can load the ADC result from the ADC data register directly to a CPU register if the function only uses that data locally and is "short". it's possible that data may never be stored in SRAM.
Now, whether you use DMA or an interrupt to transfer your data, interrupts are certainly easier to comprehend from a data flow point of view. Additionally, interrupts allow you to respond sample by sample, which may be necessary for your application. The down side is that it forces you to eat the overhead costs of entering and exiting an interrupt. That might matter for your application or not.
If you must do so much processing, that time is precious and you can not afford to operate on one sample at a time, DMA can get you out of that bind. DMA allows you to amortize the interrupt enter/exit costs over many samples (depending on your deadline). Additionally, there are some math algorithms which are much more efficient when performed over buffers rather than sample-by-sample as they arrive. Again, it will depend on your application.
Unless you spell out your applications requirements, it's impossible to tell which is the best approach.
$endgroup$
$begingroup$
Thanks for the long and comprehensive answer. First, i have to start the conversion at a very specific time (see my comment to other answer) and i also edited the first paragraph of my question. So in essence the conversion has to be started by the interrupt and now the question is rather to save this value with or without DMA. If i use the DMA, cant it lead to concurency issues ? For example when i start the conversation in the interrupt (with DMA) and move on directly to process it with in the interrupt, isnt it possible that the data isnt still there ?
$endgroup$
– Firat.Berk.Cakar
13 hours ago
$begingroup$
FWIW, if you really need exact timing, when you read the reference manual carefully, you'll see the ADC can be hardware triggered by the PDB which can be triggered by the Flex Timer. If you set your hardware up correctly, you will not need to interrupt to start the conversion.
$endgroup$
– pgvoorhees
10 hours ago
add a comment |
$begingroup$
My question is, since i have to put the conversion result into CPU to be processed anyhow, cant i just store it directly in processor registers without involving DMA or SRAM at all and process is right away?
No, this is not possible in an Cortex-M4. Moreover, you would not want this to be possible. To make it clear why: If you write your program in "not assembly", then you're going to use a compiler. Compilers generally abide by the ARM ABI which will let them use registers for data processing. What you are suggesting will cause both the compiler and the ADC to use the same location for different purposes at the same time. Your program will behave badly. You will have no way of telling a compiler that a certain register is off limits.
Of course, not involving the DMA is way slower:
ADC_result -> CPU -> SRAM -> CPU -> finally getting processed.
This isn't quite correct or incorrect. It's application specific. An interrupt can load the ADC result from the ADC data register directly to a CPU register if the function only uses that data locally and is "short". it's possible that data may never be stored in SRAM.
Now, whether you use DMA or an interrupt to transfer your data, interrupts are certainly easier to comprehend from a data flow point of view. Additionally, interrupts allow you to respond sample by sample, which may be necessary for your application. The down side is that it forces you to eat the overhead costs of entering and exiting an interrupt. That might matter for your application or not.
If you must do so much processing, that time is precious and you can not afford to operate on one sample at a time, DMA can get you out of that bind. DMA allows you to amortize the interrupt enter/exit costs over many samples (depending on your deadline). Additionally, there are some math algorithms which are much more efficient when performed over buffers rather than sample-by-sample as they arrive. Again, it will depend on your application.
Unless you spell out your applications requirements, it's impossible to tell which is the best approach.
$endgroup$
My question is, since i have to put the conversion result into CPU to be processed anyhow, cant i just store it directly in processor registers without involving DMA or SRAM at all and process is right away?
No, this is not possible in an Cortex-M4. Moreover, you would not want this to be possible. To make it clear why: If you write your program in "not assembly", then you're going to use a compiler. Compilers generally abide by the ARM ABI which will let them use registers for data processing. What you are suggesting will cause both the compiler and the ADC to use the same location for different purposes at the same time. Your program will behave badly. You will have no way of telling a compiler that a certain register is off limits.
Of course, not involving the DMA is way slower:
ADC_result -> CPU -> SRAM -> CPU -> finally getting processed.
This isn't quite correct or incorrect. It's application specific. An interrupt can load the ADC result from the ADC data register directly to a CPU register if the function only uses that data locally and is "short". it's possible that data may never be stored in SRAM.
Now, whether you use DMA or an interrupt to transfer your data, interrupts are certainly easier to comprehend from a data flow point of view. Additionally, interrupts allow you to respond sample by sample, which may be necessary for your application. The down side is that it forces you to eat the overhead costs of entering and exiting an interrupt. That might matter for your application or not.
If you must do so much processing, that time is precious and you can not afford to operate on one sample at a time, DMA can get you out of that bind. DMA allows you to amortize the interrupt enter/exit costs over many samples (depending on your deadline). Additionally, there are some math algorithms which are much more efficient when performed over buffers rather than sample-by-sample as they arrive. Again, it will depend on your application.
Unless you spell out your applications requirements, it's impossible to tell which is the best approach.
answered 14 hours ago
pgvoorheespgvoorhees
1,82599
1,82599
$begingroup$
Thanks for the long and comprehensive answer. First, i have to start the conversion at a very specific time (see my comment to other answer) and i also edited the first paragraph of my question. So in essence the conversion has to be started by the interrupt and now the question is rather to save this value with or without DMA. If i use the DMA, cant it lead to concurency issues ? For example when i start the conversation in the interrupt (with DMA) and move on directly to process it with in the interrupt, isnt it possible that the data isnt still there ?
$endgroup$
– Firat.Berk.Cakar
13 hours ago
$begingroup$
FWIW, if you really need exact timing, when you read the reference manual carefully, you'll see the ADC can be hardware triggered by the PDB which can be triggered by the Flex Timer. If you set your hardware up correctly, you will not need to interrupt to start the conversion.
$endgroup$
– pgvoorhees
10 hours ago
add a comment |
$begingroup$
Thanks for the long and comprehensive answer. First, i have to start the conversion at a very specific time (see my comment to other answer) and i also edited the first paragraph of my question. So in essence the conversion has to be started by the interrupt and now the question is rather to save this value with or without DMA. If i use the DMA, cant it lead to concurency issues ? For example when i start the conversation in the interrupt (with DMA) and move on directly to process it with in the interrupt, isnt it possible that the data isnt still there ?
$endgroup$
– Firat.Berk.Cakar
13 hours ago
$begingroup$
FWIW, if you really need exact timing, when you read the reference manual carefully, you'll see the ADC can be hardware triggered by the PDB which can be triggered by the Flex Timer. If you set your hardware up correctly, you will not need to interrupt to start the conversion.
$endgroup$
– pgvoorhees
10 hours ago
$begingroup$
Thanks for the long and comprehensive answer. First, i have to start the conversion at a very specific time (see my comment to other answer) and i also edited the first paragraph of my question. So in essence the conversion has to be started by the interrupt and now the question is rather to save this value with or without DMA. If i use the DMA, cant it lead to concurency issues ? For example when i start the conversation in the interrupt (with DMA) and move on directly to process it with in the interrupt, isnt it possible that the data isnt still there ?
$endgroup$
– Firat.Berk.Cakar
13 hours ago
$begingroup$
Thanks for the long and comprehensive answer. First, i have to start the conversion at a very specific time (see my comment to other answer) and i also edited the first paragraph of my question. So in essence the conversion has to be started by the interrupt and now the question is rather to save this value with or without DMA. If i use the DMA, cant it lead to concurency issues ? For example when i start the conversation in the interrupt (with DMA) and move on directly to process it with in the interrupt, isnt it possible that the data isnt still there ?
$endgroup$
– Firat.Berk.Cakar
13 hours ago
$begingroup$
FWIW, if you really need exact timing, when you read the reference manual carefully, you'll see the ADC can be hardware triggered by the PDB which can be triggered by the Flex Timer. If you set your hardware up correctly, you will not need to interrupt to start the conversion.
$endgroup$
– pgvoorhees
10 hours ago
$begingroup$
FWIW, if you really need exact timing, when you read the reference manual carefully, you'll see the ADC can be hardware triggered by the PDB which can be triggered by the Flex Timer. If you set your hardware up correctly, you will not need to interrupt to start the conversion.
$endgroup$
– pgvoorhees
10 hours ago
add a comment |
$begingroup$
There are three events that matter here:
- ADC start of conversion
- ADC end of conversion
- Deadline for updating PWM duty cycle
Your start of conversion should be triggered by hardware. It sounds like your PWM is already doing this.
You have to do the processing between the end of conversion and the deadline. The best way to do this is to have the end of conversion trigger a CPU interrupt. Your ADC should be able to do this. In the ISR, the CPU can do the processing and update the duty cycle.
If you're writing C code, you don't need to worry about SRAM and registers. Just read the ADC result into an integer variable. Here's some pseudo-code:
void ADC_EOC_ISR(void)
{
uint16_t adc_result = *ADC_RESULT_REG_ADDR;
uint16_t new_duty_cycle_value = compute_new_duty_cycle(adc_result);
*PWM_DUTY_CYCLE_REG = new_duty_cycle_value;
}
uint16_t compute_new_duty_cycle(uint16_t feedback)
{
... //Do processing here
}
The exact method for accessing the ADC result and PWM duty cycle registers depends on what MCU you're using and what header files/drivers have been provided.
$endgroup$
add a comment |
$begingroup$
There are three events that matter here:
- ADC start of conversion
- ADC end of conversion
- Deadline for updating PWM duty cycle
Your start of conversion should be triggered by hardware. It sounds like your PWM is already doing this.
You have to do the processing between the end of conversion and the deadline. The best way to do this is to have the end of conversion trigger a CPU interrupt. Your ADC should be able to do this. In the ISR, the CPU can do the processing and update the duty cycle.
If you're writing C code, you don't need to worry about SRAM and registers. Just read the ADC result into an integer variable. Here's some pseudo-code:
void ADC_EOC_ISR(void)
{
uint16_t adc_result = *ADC_RESULT_REG_ADDR;
uint16_t new_duty_cycle_value = compute_new_duty_cycle(adc_result);
*PWM_DUTY_CYCLE_REG = new_duty_cycle_value;
}
uint16_t compute_new_duty_cycle(uint16_t feedback)
{
... //Do processing here
}
The exact method for accessing the ADC result and PWM duty cycle registers depends on what MCU you're using and what header files/drivers have been provided.
$endgroup$
add a comment |
$begingroup$
There are three events that matter here:
- ADC start of conversion
- ADC end of conversion
- Deadline for updating PWM duty cycle
Your start of conversion should be triggered by hardware. It sounds like your PWM is already doing this.
You have to do the processing between the end of conversion and the deadline. The best way to do this is to have the end of conversion trigger a CPU interrupt. Your ADC should be able to do this. In the ISR, the CPU can do the processing and update the duty cycle.
If you're writing C code, you don't need to worry about SRAM and registers. Just read the ADC result into an integer variable. Here's some pseudo-code:
void ADC_EOC_ISR(void)
{
uint16_t adc_result = *ADC_RESULT_REG_ADDR;
uint16_t new_duty_cycle_value = compute_new_duty_cycle(adc_result);
*PWM_DUTY_CYCLE_REG = new_duty_cycle_value;
}
uint16_t compute_new_duty_cycle(uint16_t feedback)
{
... //Do processing here
}
The exact method for accessing the ADC result and PWM duty cycle registers depends on what MCU you're using and what header files/drivers have been provided.
$endgroup$
There are three events that matter here:
- ADC start of conversion
- ADC end of conversion
- Deadline for updating PWM duty cycle
Your start of conversion should be triggered by hardware. It sounds like your PWM is already doing this.
You have to do the processing between the end of conversion and the deadline. The best way to do this is to have the end of conversion trigger a CPU interrupt. Your ADC should be able to do this. In the ISR, the CPU can do the processing and update the duty cycle.
If you're writing C code, you don't need to worry about SRAM and registers. Just read the ADC result into an integer variable. Here's some pseudo-code:
void ADC_EOC_ISR(void)
{
uint16_t adc_result = *ADC_RESULT_REG_ADDR;
uint16_t new_duty_cycle_value = compute_new_duty_cycle(adc_result);
*PWM_DUTY_CYCLE_REG = new_duty_cycle_value;
}
uint16_t compute_new_duty_cycle(uint16_t feedback)
{
... //Do processing here
}
The exact method for accessing the ADC result and PWM duty cycle registers depends on what MCU you're using and what header files/drivers have been provided.
answered 13 hours ago
Adam HaunAdam Haun
17k33377
17k33377
add a comment |
add a comment |
$begingroup$
Using DMA turns your hard realtime problem (process the sample before the next sample is overwritten) into a soft realtime problem (process samples faster than they accrue in the buffer and before the buffer gets full).
Hard realtime problems are annoying to handle, you usually need an interrupt source that is synchronous with the ADC (either a "conversion finished" interrupt from the ADC, or a periodic timer interrupt that also starts ADC conversion), which means that your CPU will spend quite a large amount of time entering and exiting interrupt handlers.
That can be a valid design if the ADC clock is slow enough that the interrupt handler finishes before the next interrupt arrives, and this is the highest priority interrupt (so other interrupt handlers do not stop data processing), but this is an engineering trade-off: the DMA based design is simpler, so unless delay and jitter need to be tightly controlled, it is likely the better choice.
$endgroup$
add a comment |
$begingroup$
Using DMA turns your hard realtime problem (process the sample before the next sample is overwritten) into a soft realtime problem (process samples faster than they accrue in the buffer and before the buffer gets full).
Hard realtime problems are annoying to handle, you usually need an interrupt source that is synchronous with the ADC (either a "conversion finished" interrupt from the ADC, or a periodic timer interrupt that also starts ADC conversion), which means that your CPU will spend quite a large amount of time entering and exiting interrupt handlers.
That can be a valid design if the ADC clock is slow enough that the interrupt handler finishes before the next interrupt arrives, and this is the highest priority interrupt (so other interrupt handlers do not stop data processing), but this is an engineering trade-off: the DMA based design is simpler, so unless delay and jitter need to be tightly controlled, it is likely the better choice.
$endgroup$
add a comment |
$begingroup$
Using DMA turns your hard realtime problem (process the sample before the next sample is overwritten) into a soft realtime problem (process samples faster than they accrue in the buffer and before the buffer gets full).
Hard realtime problems are annoying to handle, you usually need an interrupt source that is synchronous with the ADC (either a "conversion finished" interrupt from the ADC, or a periodic timer interrupt that also starts ADC conversion), which means that your CPU will spend quite a large amount of time entering and exiting interrupt handlers.
That can be a valid design if the ADC clock is slow enough that the interrupt handler finishes before the next interrupt arrives, and this is the highest priority interrupt (so other interrupt handlers do not stop data processing), but this is an engineering trade-off: the DMA based design is simpler, so unless delay and jitter need to be tightly controlled, it is likely the better choice.
$endgroup$
Using DMA turns your hard realtime problem (process the sample before the next sample is overwritten) into a soft realtime problem (process samples faster than they accrue in the buffer and before the buffer gets full).
Hard realtime problems are annoying to handle, you usually need an interrupt source that is synchronous with the ADC (either a "conversion finished" interrupt from the ADC, or a periodic timer interrupt that also starts ADC conversion), which means that your CPU will spend quite a large amount of time entering and exiting interrupt handlers.
That can be a valid design if the ADC clock is slow enough that the interrupt handler finishes before the next interrupt arrives, and this is the highest priority interrupt (so other interrupt handlers do not stop data processing), but this is an engineering trade-off: the DMA based design is simpler, so unless delay and jitter need to be tightly controlled, it is likely the better choice.
answered 10 hours ago
Simon RichterSimon Richter
6,61511128
6,61511128
add a comment |
add a comment |
Thanks for contributing an answer to Electrical Engineering Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2felectronics.stackexchange.com%2fquestions%2f434057%2fprocessing-adc-conversion-result-dma-vs-processor-registers%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
$begingroup$
You write in a comment that you are "implementing a motor control algorithm." In almost all such circumstances I've experienced, this required very carefully designed sample-to-output timing. I will tend to keep the sample-to-sample measurement cycle-exact from one to the next (this can be achieved with DMA or, often enough, without DMA) and also keep the time from sample-to-output as close to cycle-exact as I can achieve. This almost always means "some assembly" mixed with C. If not, the closed loop control isn't competitive enough and will fail to my betters in the marketplace, eventually.
$endgroup$
– jonk
11 hours ago
$begingroup$
I should have added this: I also keep the sample-to-output as short as possible. Short is even more important than consistent timing, though both are important. A control algorithm can accept some inconsistency in the delay, if the delay is very short. But long delays -- and especially long delays with variability to them -- are certain death. Keep things as tight and close as possible and keep the variability as minimal as you can achieve. The rest will just follow, if you can do that.
$endgroup$
– jonk
11 hours ago
$begingroup$
What is the dominant pole in the motor?
$endgroup$
– copper.hat
3 hours ago