This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

assembly code = higher speed?



Hi!

I have to use an external ADC and I'd like to know if writting the operations needed for the conversion (shift and addition) in assembly will increase the speed?  I know the CLA does mutiplication and addition in 1 cycle. Will I get that if I write that part of the code in assembly, or it has nothing to do with this?

Many thanks,

Monica

  • Monica,

    If you just performing a shift+addition on the ADC results, I would not worry about making it assembly, especially if the rest of your code is in C.

    Regards,
    Daniel

  • Monica Zolog said:
    increase the speed

    Relative to what?

    If the code  you already have is optimal then, obviously, no increase is possible!

    Just like buying a top-class piano will not, of itself, make you a great pianist neither will using assembler of itself make you a great programmer.
    It takes a great deal of skill and experience to use assembler effectively - particularly to out-smart a good, optimising compiler...

     

  • Relative to the code written in C.

    I don't know how I can optimize the code. I must read 16 GPIOs, do the shifting and addition to get the ADC result. All this 12 times.  Is there something  I could do? I mean is here something to optimize?

    Thanks a lot,

    Monica

  • You mentioned that you're doing something 12 times.

    Since this appears to be a constant number, have you tried loop unrolling in C?  If you avoid using "for", you'll save about 8 cycles per iteration.

  • Hi Monica,

    I am assuming you have external ADC, which is connected to the MCU/DSP. And you are reading the result through the GPIO.

    In this case I would recommend using external memory interface, if available.

     

    Regards, Mitja

  • Monica Zolog said:

    I don't know how I can optimize the code. I must read 16 GPIOs, do the shifting and addition to get the ADC result. All this 12 times.  Is there something  I could do? I mean is here something to optimize?

    Monica,

    What frequency are you trying to sample at? 
    What frequency is your control loop code supposed to run at?

    One reason for using assembly instead of C code is to minimize cycle counts in your control loop so that you can run it at a high frequency.  Depending on your application requirements, this might not even be something you need to worry about.

    Also, depending on your ADC sample rate, optimization of the code for reading ADC results may or may not be needed.

  • Yes, I'm using an external ADC on 16 bits (probably a 14bits one in the end). The sampling rate is 9KHz. The control loop must run at the same frequency. According to my measurements, reading the 16 GPIOs takes 1.5us. Adding to this the shifting and addition operations, scaling to volts, signaling to the ADC, I got about 3us per conversion. It is possible that the rest of the time left to 111.111us will be enough for the control loop, but the number of control features can increase, you never know all the requirements from the beginning.

     

  • Hi Monica

    As many hava said before me:

    Do not optimize unless you really really really need to. Optimizing just for the sake of optimizing is a waste of time (thou it gives you a warm and fuzzy feeling of a job well done) and in many cases results in a lot more work further along a project development. And when you are optimizing, optimize the part which will give you the biggest gain.

    If you are fresh to programming field, and even if you are a veteran, I'd recommend reading "Code Complete". It offers a lot of knowledge on topic of programing, so it gives you a chance to learn on somebody else's mistakes.

    So in your case, I'd recommend to move on, build a complete application, and then optimize if needed.

    Regards, Mitja

  • Thank you very much for the advice!

    This was exactly my thought, that I will make a better job if I spent some time on optimizing the code. I'll leave this for the moment and move to the next step. In the meantime, I'm waiting for 'Code complete' to get on my desk :)

    Thanks again!

    Best regards,

    Monica