PDA

View Full Version : PIC18Fxx math 24 & 32 bit



ronsimpson
- 30th November 2006, 15:14
I am working on a DSP project. I need more speed.
I converted from PIC16F to PIC18F and that helped!! (8bit * 8 bit)
I am looking for ASM code for PIC18F math (24 & 32 bit) *,-,+,/, shift
I have PIC16F math but cannot find 18F libraries.

MicroChip thinks I should convert to C but I want to stay with PBP for everything but the ‘fast math loop’. PBP has very good IO.

Thanks

Acetronics2
- 30th November 2006, 15:21
Hi Ron

Nothing Here ??? : http://www.melabs.com/resources/fp.htm

...

But µChip is right ... Power, exp and "complex" ( laughs ...) mathematics are easily supported by C ... or other Basic Compilers.
Basic is a fair language ... but it takes its time ... may be a Swiss or Belgian invention ???

Alain

keithdoxey
- 30th November 2006, 15:55
Basic is a fair language ... but it takes its time ... may be a Swiss or Belgian invention ???


So thats what BASIC stands for....

Belgians And Swiss Invented Code :)

mister_e
- 1st December 2006, 03:19
There's no need to switch to C or else language for 24bit maths IF YOU WANT to spend some time in the code development. There's tons of example here and there (most in assembler but anyways).

Depending what you need to work with trigs (sin cos tan.... ) Biquad eqs? FFT?

Question is always the same.... do you reallly need to use those maths? They're always slow and code inefficient anyways.

ronsimpson
- 1st December 2006, 17:32
I can find “tons of examples” in PIC16 and smaller! I can not find any thing in PIC18F.
There are many web hits on PIC18F math but it is all PIC16F and smaller.

I am trying to find the RMS value of 4 audio streams.
I have it running on a bigger computer.
Read in ADC(9:0) 10 bits.
Absolute value(7:0) 8 bits. Loose the sign and drop one bit.
Square ADC^2(15:0) 16 bits
Output(23:8)=Output-from last time(23:0)-((Output(23:8)-ADC^2(15:0))/256)
Convert to db.

I have the convert to db happening very fast.
The Square is fast on the PIC18F. very slow in the PIC16
The average formula finds the e^-t average just like a Resistor Capacitor finds the average. How does it work? Compare input value to the average form last time. We are only concerned with the difference. The difference is divided by some amount (that is the time constant 256) and subtracted from the average. In this type of averaging recent samples greatly effect the output, but averages hundreds of samples ago have only a little effect. (and it takes up very little RAM)
It takes no code to divide by 256. Actually I want to divide by 1024 but I think there is no time to do the shifting. There is a 24 bit – 16 bit that is hard to do in PBP.
I coded part of it in PBP and looked at the output. PBP spends a lot of time moving the variables to temp, calling a subroutine, and moving the variables back from temp, then turning around and moving the same variables back into temp for the next call subroutine.

I am trying some nasty games like:
AverageUpper= bits 23:8 while AverageLower= bits 15:0 of the same 24 bit number. Using overlapping memory space. That way I can use the 16 bit math in PBP.

Considering the speed problem I should use assembly. I had it running on a PIC10 in assembler, just for a joke. If a PIC10 running 4mhz with no multiply can do the job s-l-o-w-l-y, then it should run in a PIC18 at 40mhz.

I want to keep PBP for the LCD and IO functions.

Acetronics2
- 1st December 2006, 17:47
Hi, Ron

There are tons of dedicated circuits, able to do that ... I think to SSM "squad", i.e.

after, you do what you want as kind of numeric treatment ...

Why use the Phoenix missile ... for killing a little fly.

Alain

Luciano
- 1st December 2006, 19:17
Hi Alain,

Niklaus E. Wirth a Swiss computer scientist was the chief designer of the
programming languages Algol W, Pascal, Modula, Modula-2, and Oberon.

* * *

Jean Ichbiah (Members of the French Academy of Sciences) was the chief
designer of the ADA programming language, from 1977–1983. At the time,
he was a member of the Programming Research division at CII Honeywell
Bull (CII-HB) in Louveciennes, France.


Famous code written in ADA:
http://www.ima.umn.edu/~arnold/disasters/ariane.html

http://www.rvs.uni-bielefeld.de/publications/Incidents/DOCS/ComAndRep/Ariane/Esa/ariane5/COPY/ariane5rep.html

Best regards,

Luciano

paul borgmeier
- 1st December 2006, 19:57
Have you seen this? (I am not sure it has what you want)

http://www.piclist.com/techref/member/RF-AMY-K22a/mathsdefs_h.htm

Also, you might want to post your ASM request here

http://forum.microchip.com/tt.aspx?forumid=7

Many strong ASM programmers visit this mirochip site.

Good Luck,

Acetronics2
- 2nd December 2006, 12:52
Famous code written in ADA:
http://www.ima.umn.edu/~arnold/disasters/ariane.html

Best regards,

Luciano

I' ve seen the word DISASTER somewhere in your link ... didn't I ???

hi,hi,hi ...

Alain