Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

uC with 16 bit division instruction

Status
Not open for further replies.

le_chiffre

New Member
Hi. I'm searching a uC with a 16 bits/16 bits division instruction, for making a fast division with a low clock.16 bits / 16 bits division by software in 8 bit uC is very slow, and I don't want to use a fast clock because I need it for a portatil device (and fast clocks burns the batteries very quickly). I looking for a small and cheap uC, with just a few I/O pins, maybe with ( but not mandatory) a serial mode. Do you know something like this? Thank you
 
dsPIC30F2010 or dsPIC30F4012? (or any other dsPIC30F really- the 33Fs are too big for you).
 
Although the 18 series pics are 8 bit, a 16 bit divide only takes 28 cycles. Something like a 18F1220 should do it. With the proper use of idle modes your power consumption should be minimal.

Mike.
 
Dividing by a constant is fairly easy using shift instructions.

How accurate does it need to be?
 
Thank you all for the replys. I'll be looking for your recommendations when I get home. I need the division for an interpolation algorithm for synthetizing a signal. I need to make 3 divisions in aprox. 2 ms. I'm using a 89s52, and the division rutine I found is very slow. I have some ideas how to improve my interpolation algorithm, but the true is that, even improving my algorithm, I think my design could benefit from changin the uC. 89s52 has too many pins that I don't need, I only used it because I knew it, is easy to program, and I had one in the closet.
This 3 divisions routines that I'm calling are taking... I don't know.... 90% of the CPU time...

Thank you again
 
Linear interpolation is fairly easy using shifts, for example if one sample reads 4, the next is 6, approximating the intermediate value is easy without using division at all:
6 - 4 = 2
2 shl 1 = 1
4 + 1 = 5
 
Hero999 said:
Linear interpolation is fairly easy using shifts, for example if one sample reads 4, the next is 6, approximating the intermediate value is easy without using division at all:
6 - 4 = 2
2 shl 1 = 1
4 + 1 = 5

Did you mean shr? ;) He has to pay attention to the sign, though. If the first sample is 4 and the second is 6
4 - 6 = -2
-2 shr 1 = ...

le_chiffre, from your first post I understand that you would like to send data through a serial interface. Why don't you let the computer do the interpolation of the samples?
 
Hero999 said:
Linear interpolation is fairly easy using shifts, for example if one sample reads 4, the next is 6, approximating the intermediate value is easy without using division at all:
6 - 4 = 2
2 shl 1 = 1
4 + 1 = 5

Nice! But, sadly, my interpolation is more like cubic, and it needs to divide by numbers up to 16 bits. Thanks anyway

eng1 said:
le_chiffre, from your first post I understand that you would like to send data through a serial interface. Why don't you let the computer do the interpolation of the samples?

The serial interface is from the uC to an DAC that take the digital data as serial. Anyway, thanks for the idea
 
Nigel Goodwin said:
I would suggest you give full details of exactly what you're wanting to do, as it is people can only guess!.

You're right. I just don't write english very well and I was trying to minimize the writing.

I'm making an ECG (electrocardiogram) synthetizer/simulator. You load the interesting points of a ECG in the uC (you load the position(time since the last point, 0-~100, I don´t remember) and amplitud (0-255) of the PQRST points, and the frequency of the hearth beat) , and this algorithm interpoles the values of the ECG between two consecutives points at 2 ms intervales. For example, you say that Q comes 30 ms after P, and have an amplitud of 20. So the algorithm calculates since2ms , every 2 ms, until 60 ms, the intermediate points. This interpolation is cubic
, and the critic term is:
-2*[ y (T) – y (0) ]*t^3 / T^3
wherte y(t) is the amplitud of the ECG at time t, and T is the duration of the segment (t<T always).

Because I'm using 8bit uC (89s52), this is tricky. I found a math library to multiply or divide two 16 bits numbers, but I must be carefull that the multiplication result doesn't go beyond 16 bits (T^3 >>16bits), or I will not be able to divide. Also, I need to avoid dividing t/T at the begining because result is always zero + reminder. So I first multiply 2*[ y (T) – y (0) ] by t, then divide by T. Then multiply again by t, then divide by T. One more time, *t/T.
This method works pretty fine, with some error when rounding the divisions.
My problem is that 2*[ y (T) – y (0) ]*t can be > than 8 bits... in fact, if I not carefull with the values, can be > than 16 bits.

Well, that's pretty much the picture. Some points:
- The truth is that I need to divide 16 bits by 8 bits, but I didn't find this algorithm, which probably is much faster than 16bits/16bits, and I don't have the knowledge neither the will to try to write it.
- The ECG is periodic, so technically, I can calculate every point at the start of the program, and then just output then. The problem is that the 89s52 has only 256by ram (I think I calculate aprox 400 different values), and I don't want to use external RAM.
I think that the best idea is not to do the cubic interpolation for every point, but just for some at the star of the program (maybe 100 values ) and use linear interpolation for the rest of the values. This could be very interesting, because it would allow me to reduce A LOT the speed of the oscillator (practically as much as I want) , and this is probably the line I will follow

But I still want to hear about cheap, small, and simple 16 bits uC (if they exists), or at least something equivalent to the 89s52 with 16 bits.

Are you still there? Had you read all this? Thank you!
 
If this is just a simulator why can't you simply store 1 beat in program memory and scale it to produce differing amplitudes and step through the table using a counter to alter the heart rate.

So, you might store 100 bytes that range in value from 0 to 255. If you display (output) these values at 1 every 10mS then you get a heart beat of 60bpm. 5mS = 120bpm Etc.

Depending on what resolution you require you could store 1000 16bit points.

Mike.
 
Use a higher level programming language such as mikroBasic and PIC's, and you needn't worry about complex equations!

Sometimes you will have to break it up (Proton development suit only accepts 3 arguments per equation) eg,

A = ((X * Y / Z)) * W / 4

would have to be changed to

A = X * Y / Z

A = A * W / 4

mikroBasic doesn’t have this limit from memory.

One other limitation, just say your using Floats (a variable type that can store numbers from -2147483646.999 to +2147483646.999) and Words (0 - 65535) in the same equation, you will experience "clipping" if the result is > 65535 or contains decimals, as the Word type is limited to a smaller range.

eg;

Dim Var1 as Float
Dim Var2 as Word

Var2 = 12345
Var1 = Var2 * 1000.001

That should make Var1 = 12345012.345 but it will be clipped to 45012 as Var2 can only hold 5 digits(max 65535) and no decimal places.

The easy way around this, use Tempory registers, eg

Dim Var1 as Float
Dim Var2 as Float
Dim Temp_FLT as Float

Var2 = 12345
Temp_Float = Var2

Var1 = Var2 * 1000.001

Now Var1 will return the correct value

You can use this analogy for your problem with 8 bit and 16 bit registers as well
 
dknguyen said:
dsPIC30F2010 or dsPIC30F4012? (or any other dsPIC30F really- the 33Fs are too big for you).

Ain't nothing "bigger" about the 33F in a negative sense. They're cheap, more powerful, nifty DMA capabilities, and consume MUCH less power! But they're 3.3V Vdd only, 5v-tolerant pins. A downside is SLEEP mode current is higher than other PICs.

IIRC a 16x16 hardware divide takes up 17 cycles on a 33F, you use a REPEAT 17 instruction before the divide instruction.

But if a 16-bit divide takes only 28 cycles and you need to do 3x in 2msec, I don't see the prob. This is like 0.5% of your capabilities which isn't much to speak of!
 
Actually I should have mentioned the 33F can do a 16-bit divide as a Fractional Multiply and do it in one cycle.

Basically a Fractional Multiply is multiplying two 16-bit numbers together and
then right-shifting 16 bits. So if we have a constant "X" that is (MAX_INT/3), fractional mult of 100*X is 33. This is essentially a divide with the divisor stated a bit differently.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top