Author Topic: some newbie question for integer DSP  (Read 1550 times)

0 Members and 1 Guest are viewing this topic.

Offline ali_asadzadehTopic starter

  • Super Contributor
  • ***
  • Posts: 1905
  • Country: ca
some newbie question for integer DSP
« on: April 20, 2017, 01:34:25 pm »
Hi,
I'm a newbie in the fix-point DSP, I have some basic question,

Suppose that I have an ARM CPU with a 12bit ADC and I have configured the PWM to be 9bit  , I wanted to do for example a PID algorithm in Q15 format

I have done it successfuly with float numbers, But for increasing the Speed I wanted to do it in Q15 format

how should I convert my ADC readings, KP, Ki, Kd and PWM values to Q15?

suppose that I have a kp = 1.0 Ki=1.0 and Kd =1.0

I guess that I should shift the ADC readings 3 times to left to convert them to Q15 ? what about the other values? would some one explain the concept or relate a good link for understanding.

Thanks in advance
ASiDesigner, Stands for Application specific intelligent devices
I'm a Digital Expert from 8-bits to 64-bits
 

Offline ali_asadzadehTopic starter

  • Super Contributor
  • ***
  • Posts: 1905
  • Country: ca
Re: some newbie question for integer DSP
« Reply #1 on: April 21, 2017, 05:42:35 pm »
Hi,
I realy need some help or a good reference, do you recommend some thing?
ASiDesigner, Stands for Application specific intelligent devices
I'm a Digital Expert from 8-bits to 64-bits
 

Online Someone

  • Super Contributor
  • ***
  • Posts: 4531
  • Country: au
    • send complaints here
Re: some newbie question for integer DSP
« Reply #2 on: April 21, 2017, 11:55:06 pm »
The design will depend a lot on your target, a DSP with a single cycle MAC and barrel shifters will result in a very different design to a generic CPU with a deep pipeline, again a different design to an ASIC or FPGA. But the basic steps are:
  • Simulate the entire system with floating point numbers until it works.
  • Determine the largest values possible in each step of the calculations.
  • Select scalings to avoid overflow or wraparound.
  • Simulate again with the fixed point variables at each step
  • Return to step 3 and increase precision if the solution wont stabilise or converge.
  • Reimplement on the target and test, return to step 1.
Reducing computational cost in step 3 is the time consuming part and needs a good understanding of the architecture of the target, for your first designs its a lot simpler if you use just a single format for the entire path, then go back and optimise out the parts that are too wide.
 

Offline hamster_nz

  • Super Contributor
  • ***
  • Posts: 2803
  • Country: nz
Re: some newbie question for integer DSP
« Reply #3 on: April 22, 2017, 06:14:49 am »
The design will depend a lot on your target, a DSP with a single cycle MAC and barrel shifters will result in a very different design to a generic CPU with a deep pipeline, again a different design to an ASIC or FPGA. But the basic steps are:
  • Simulate the entire system with floating point numbers until it works.
  • Determine the largest values possible in each step of the calculations.
  • Select scalings to avoid overflow or wraparound.
  • Simulate again with the fixed point variables at each step
  • Return to step 3 and increase precision if the solution wont stabilise or converge.
  • Reimplement on the target and test, return to step 1.
Reducing computational cost in step 3 is the time consuming part and needs a good understanding of the architecture of the target, for your first designs its a lot simpler if you use just a single format for the entire path, then go back and optimise out the parts that are too wide.

^^^ This is the a very well through out reply.

In step 2 (work out the scaling factors) don't just simulate or test, but always look for the worst possible case. Just because a DSP filter has a nominal gain of 1.0 doesn't mean that the output will have the same range as the input - most filters have a small amount of ripple/overshoot/ringing that will need additional range (or slightly less gain) to ensure it doesn't fail due to overflow.

For unsigned binary, here are some rules of thumb.

For addition of two n.m-bit numbers, you need (n+1).m bits of precision on the output

For multiplication of two n.m-bit numbers you need 2n.2m bits in the results to not lose precision in the result.

For division by something that changes dynamically all bets are off : e.g. 1/65535 vs 65535/1

For division by a constant you can work out a sensible amount of precision in the result, but it will always need more digits to the right of the decimal than you would like - unless it is division by a power of 2 (e.g. 0.1 as a binary decimal is 0.0001100110011001...). So avoid division if at all possible, unless it is by a constant power of two (where you can just move the decimal point). For example it might be better to replace n/3 with (n/2 + n/8 + n/32) which totals to n/0.65625.

For signed numbers these changes and has a few more corner cases as the ranges are asymmetric - there is usually one more valid negative value than positive ones. For example for multiplication of n-bit signed numbers, the result of multiplication doesn't fit in an n-bit signed number (e.g. (-1) * (-128) gives 128, which isn't a valid 8-bit signed number)
Gaze not into the abyss, lest you become recognized as an abyss domain expert, and they expect you keep gazing into the damn thing.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf