Processing ADC conversion result: DMA vs Processor RegistersSTM32F103 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

With a Canadian student visa, can I spend a night at Vancouver before continuing to Toronto?

US visa is under administrative processing, I need the passport back ASAP

A Strange Latex Symbol

Why is it that the natural deduction method can't test for invalidity?

Noun clause (singular all the time?)

What's the polite way to say "I need to urinate"?

How to have a sharp product image?

Does Gita support doctrine of eternal cycle of birth and death for evil people?

In order to check if a field is required or not, is the result of isNillable method sufficient?

Combinable filters

How to pronounce 'C++' in Spanish

How much cash can I safely carry into the USA and avoid civil forfeiture?

Examples of subgroups where it's nontrivial to show closure under multiplication?

How to type a section sign (§) into the Minecraft client

What does it mean to express a gate in Dirac notation?

Document starts having heaps of errors in the middle, but the code doesn't have any problems in it

How did Captain America manage to do this?

Exchange,swap or switch

To say I met a person for the first time

Why does nature favour the Laplacian?

Is the 5 MB static resource size limit 5,242,880 bytes or 5,000,000 bytes?

Do I have an "anti-research" personality?

Why do Computer Science majors learn Calculus?

What language was spoken in East Asia before Proto-Turkic?



Processing ADC conversion result: DMA vs Processor Registers


STM32F103 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;








5












$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.










share|improve this question











$endgroup$







  • 2




    $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
    Apr 23 at 18:47







  • 2




    $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
    Apr 23 at 18:51











  • $begingroup$
    What is the dominant pole in the motor?
    $endgroup$
    – copper.hat
    Apr 24 at 2:41

















5












$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.










share|improve this question











$endgroup$







  • 2




    $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
    Apr 23 at 18:47







  • 2




    $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
    Apr 23 at 18:51











  • $begingroup$
    What is the dominant pole in the motor?
    $endgroup$
    – copper.hat
    Apr 24 at 2:41













5












5








5





$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.










share|improve this question











$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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Apr 23 at 16:17









JYelton

16.5k2891194




16.5k2891194










asked Apr 23 at 15:24









Firat.Berk.CakarFirat.Berk.Cakar

545




545







  • 2




    $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
    Apr 23 at 18:47







  • 2




    $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
    Apr 23 at 18:51











  • $begingroup$
    What is the dominant pole in the motor?
    $endgroup$
    – copper.hat
    Apr 24 at 2:41












  • 2




    $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
    Apr 23 at 18:47







  • 2




    $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
    Apr 23 at 18:51











  • $begingroup$
    What is the dominant pole in the motor?
    $endgroup$
    – copper.hat
    Apr 24 at 2:41







2




2




$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
Apr 23 at 18:47





$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
Apr 23 at 18:47





2




2




$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
Apr 23 at 18:51





$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
Apr 23 at 18:51













$begingroup$
What is the dominant pole in the motor?
$endgroup$
– copper.hat
Apr 24 at 2:41




$begingroup$
What is the dominant pole in the motor?
$endgroup$
– copper.hat
Apr 24 at 2:41










5 Answers
5






active

oldest

votes


















8












$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.






share|improve this answer









$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
    Apr 23 at 15:44







  • 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
    Apr 23 at 18:06






  • 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
    Apr 23 at 18:13










  • $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
    Apr 23 at 23:30


















6












$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.






share|improve this answer









$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
    Apr 23 at 16:08










  • $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
    Apr 23 at 19:29


















3












$begingroup$

There are three events that matter here:



  1. ADC start of conversion

  2. ADC end of conversion

  3. 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.






share|improve this answer









$endgroup$




















    0












    $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.






    share|improve this answer









    $endgroup$




















      0












      $begingroup$

      I'm pretty sure you don't need to do what you want (and instead consume the ADC result directly in the interrupt as @AdamHaun suggests), but one trick that usually works is using the FPU registers. You'll have to check your compiler documentation, but with most compilers I've seen, if you don't use any float math in your code, the compiler will not touch the FPU registers (D0-D15), and you can use them yourself as a fast temporary storage.






      share|improve this answer









      $endgroup$













        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
        );



        );













        draft saved

        draft discarded


















        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

























        5 Answers
        5






        active

        oldest

        votes








        5 Answers
        5






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        8












        $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.






        share|improve this answer









        $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
          Apr 23 at 15:44







        • 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
          Apr 23 at 18:06






        • 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
          Apr 23 at 18:13










        • $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
          Apr 23 at 23:30















        8












        $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.






        share|improve this answer









        $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
          Apr 23 at 15:44







        • 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
          Apr 23 at 18:06






        • 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
          Apr 23 at 18:13










        • $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
          Apr 23 at 23:30













        8












        8








        8





        $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.






        share|improve this answer









        $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.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Apr 23 at 15:39









        TimWescottTimWescott

        7,2491416




        7,2491416











        • $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
          Apr 23 at 15:44







        • 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
          Apr 23 at 18:06






        • 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
          Apr 23 at 18:13










        • $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
          Apr 23 at 23:30
















        • $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
          Apr 23 at 15:44







        • 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
          Apr 23 at 18:06






        • 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
          Apr 23 at 18:13










        • $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
          Apr 23 at 23:30















        $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
        Apr 23 at 15:44





        $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
        Apr 23 at 15:44





        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
        Apr 23 at 18:06




        $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
        Apr 23 at 18:06




        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
        Apr 23 at 18:13




        $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
        Apr 23 at 18:13












        $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
        Apr 23 at 23:30




        $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
        Apr 23 at 23:30













        6












        $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.






        share|improve this answer









        $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
          Apr 23 at 16:08










        • $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
          Apr 23 at 19:29















        6












        $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.






        share|improve this answer









        $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
          Apr 23 at 16:08










        • $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
          Apr 23 at 19:29













        6












        6








        6





        $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.






        share|improve this answer









        $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.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Apr 23 at 15:45









        pgvoorheespgvoorhees

        1,85399




        1,85399











        • $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
          Apr 23 at 16:08










        • $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
          Apr 23 at 19:29
















        • $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
          Apr 23 at 16:08










        • $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
          Apr 23 at 19:29















        $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
        Apr 23 at 16:08




        $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
        Apr 23 at 16:08












        $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
        Apr 23 at 19:29




        $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
        Apr 23 at 19:29











        3












        $begingroup$

        There are three events that matter here:



        1. ADC start of conversion

        2. ADC end of conversion

        3. 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.






        share|improve this answer









        $endgroup$

















          3












          $begingroup$

          There are three events that matter here:



          1. ADC start of conversion

          2. ADC end of conversion

          3. 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.






          share|improve this answer









          $endgroup$















            3












            3








            3





            $begingroup$

            There are three events that matter here:



            1. ADC start of conversion

            2. ADC end of conversion

            3. 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.






            share|improve this answer









            $endgroup$



            There are three events that matter here:



            1. ADC start of conversion

            2. ADC end of conversion

            3. 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.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Apr 23 at 16:44









            Adam HaunAdam Haun

            17k33377




            17k33377





















                0












                $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.






                share|improve this answer









                $endgroup$

















                  0












                  $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.






                  share|improve this answer









                  $endgroup$















                    0












                    0








                    0





                    $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.






                    share|improve this answer









                    $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.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Apr 23 at 19:51









                    Simon RichterSimon Richter

                    6,62511128




                    6,62511128





















                        0












                        $begingroup$

                        I'm pretty sure you don't need to do what you want (and instead consume the ADC result directly in the interrupt as @AdamHaun suggests), but one trick that usually works is using the FPU registers. You'll have to check your compiler documentation, but with most compilers I've seen, if you don't use any float math in your code, the compiler will not touch the FPU registers (D0-D15), and you can use them yourself as a fast temporary storage.






                        share|improve this answer









                        $endgroup$

















                          0












                          $begingroup$

                          I'm pretty sure you don't need to do what you want (and instead consume the ADC result directly in the interrupt as @AdamHaun suggests), but one trick that usually works is using the FPU registers. You'll have to check your compiler documentation, but with most compilers I've seen, if you don't use any float math in your code, the compiler will not touch the FPU registers (D0-D15), and you can use them yourself as a fast temporary storage.






                          share|improve this answer









                          $endgroup$















                            0












                            0








                            0





                            $begingroup$

                            I'm pretty sure you don't need to do what you want (and instead consume the ADC result directly in the interrupt as @AdamHaun suggests), but one trick that usually works is using the FPU registers. You'll have to check your compiler documentation, but with most compilers I've seen, if you don't use any float math in your code, the compiler will not touch the FPU registers (D0-D15), and you can use them yourself as a fast temporary storage.






                            share|improve this answer









                            $endgroup$



                            I'm pretty sure you don't need to do what you want (and instead consume the ADC result directly in the interrupt as @AdamHaun suggests), but one trick that usually works is using the FPU registers. You'll have to check your compiler documentation, but with most compilers I've seen, if you don't use any float math in your code, the compiler will not touch the FPU registers (D0-D15), and you can use them yourself as a fast temporary storage.







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Apr 24 at 8:02









                            Dmitry GrigoryevDmitry Grigoryev

                            18.6k22878




                            18.6k22878



























                                draft saved

                                draft discarded
















































                                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.




                                draft saved


                                draft discarded














                                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





















































                                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







                                Popular posts from this blog

                                Bulk add to cart function issuecart vs. mini cart issue … rwd themeRedirect Add to cart button to cart pageAdd to cart issue - Magento 2.1The requested Payment Method is not available When creating an orderM2: reason add-to-cart might not function in production modeAdd to cart issue in some android devicesMagento 2 - custom price can not add to subtotal and grand total after add to cartAdd to cart codeIssue with my cart module on pdp and cart pages, just keeps spinningBulk price and quantity update using rest api

                                БиармияSxpst500bh2ntaf! 3h2r