Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
LinkBack Thread Tools Display Modes
Old 21st March 2007, 01:53 AM   (permalink)
Default uC with 16 bit division instruction

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
le_chiffre is offline  
Old 21st March 2007, 02:26 AM   (permalink)
Default

dsPIC30F2010 or dsPIC30F4012? (or any other dsPIC30F really- the 33Fs are too big for you).
dknguyen is offline  
Old 21st March 2007, 03:31 AM   (permalink)
Default

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.
Pommie is online now  
Old 21st March 2007, 08:37 AM   (permalink)
Default

You also might mention why you're looking for division, and exactly what division you need - they may be an alternative way?.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline  
Old 21st March 2007, 11:07 AM   (permalink)
Default

Dividing by a constant is fairly easy using shift instructions.

How accurate does it need to be?
__________________
I also post at the following sites:
http://www.stop-microsoft.org http://www.heated-debates.com
Screen name: Aloone_Jonez
And http://www.silicontronics.com, same screen name as here.
Hero999 is offline  
Old 21st March 2007, 06:31 PM   (permalink)
Default

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
le_chiffre is offline  
Old 21st March 2007, 07:33 PM   (permalink)
Default

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
__________________
I also post at the following sites:
http://www.stop-microsoft.org http://www.heated-debates.com
Screen name: Aloone_Jonez
And http://www.silicontronics.com, same screen name as here.
Hero999 is offline  
Old 21st March 2007, 10:20 PM   (permalink)
Default

Quote:
Originally Posted by Hero999
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?
eng1 is offline  
Old 22nd March 2007, 12:05 AM   (permalink)
Default

Quote:
Originally Posted by Hero999
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

Quote:
Originally Posted by eng1
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
le_chiffre is offline  
Old 22nd March 2007, 12:19 AM   (permalink)
Default

I would suggest you give full details of exactly what you're wanting to do, as it is people can only guess!.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline  
Old 22nd March 2007, 01:13 AM   (permalink)
Default

Quote:
Originally Posted by Nigel Goodwin
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!
le_chiffre is offline  
Old 22nd March 2007, 03:54 AM   (permalink)
Default

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.
Pommie is online now  
Old 22nd March 2007, 05:32 AM   (permalink)
Default

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
__________________
Spency.

PIC Micro's - Your mind is the limit

PIC's and interfacing with other devices - a PIC Basic Guide @ digital-diy.net
gramo is offline  
Old 22nd March 2007, 07:31 AM   (permalink)
Default

Quote:
Originally Posted by dknguyen
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!
__________________
I thought what I'd do was I'd pretend I was one of those deaf-mutes.
Oznog is offline  
Old 22nd March 2007, 12:09 PM   (permalink)
Default

Have you asked Google?
http://www.google.com/search?num=100...on&btnG=Search
http://www.restena.lu/convict/Jeunes...perations2.htm
http://www.azillionmonkeys.com/qed/adiv.html
__________________
I also post at the following sites:
http://www.stop-microsoft.org http://www.heated-debates.com
Screen name: Aloone_Jonez
And http://www.silicontronics.com, same screen name as here.
Hero999 is offline  
Reply

Bookmarks

Thread Tools
Display Modes



Similar Threads
Title Starter Forum Replies Latest
Need some help with a code provided by ATMEL ikalogic Micro Controllers 1 23rd January 2007 03:46 PM
8-bit microcontrollers samcheetah Micro Controllers 8 23rd December 2006 09:39 AM
PIC 12 and 14 bits instruction sets Joel Rainville Micro Controllers 4 20th September 2005 09:15 AM
PIC's call instruction hantto Micro Controllers 6 22nd March 2004 10:25 AM
Processor Instruction Format mus3na Micro Controllers 1 19th January 2004 07:13 PM



All times are GMT. The time now is 07:21 AM.


Electronic Circuits  |  Learning Electronics
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.

eXTReMe Tracker