PDA

View Full Version : how can I caculate with numbers bigger than a word using 16F88 ?



Mugelpower
- 11th May 2010, 20:52
Hi Guys & Dolls,

to make my tripmaster accurate I need to crunch bigger numbers.

my code works like this:

'---[INT - interrupt handler]---------------------------------------------------
ToggleLED1:
cnt = cnt +1
cntb = cnt * 20
meter = cntb / f0
If meter = x Then
meter = 0
km = km + 1
cnt = 0
else
Endif
@ INT_RETURN

but to get more accuracy I need cntb = cnt * 1000 with a maximum of cnt around 4000.

makes 4000000 maximum for cntb .

How could I do that fast enough in my interrupt routine?

Regards
Mugelpower

mackrackit
- 12th May 2010, 01:23
The easy way would be using an 18Fxxx with PBP 2.50 or greater. That way you have LONGs.

Other wise you are stuck with dividing down and messing with HIGH BYTE/LOW BYTE stuff. Just not worth is these days.

Charles Linquis
- 12th May 2010, 02:02
I'm trying to rid the world of 16F chips, but try this

http://www.picbasic.co.uk/forum/showthread.php?t=12433&highlight=n-bit_math

Jerson
- 12th May 2010, 05:08
What is x20?
what is f0?
what is x?

A little more detail and it is possible that a different solution exists.

The last time I did something similar, I had a pulses per mile count. After that the mile count would increase by 1. To handle numbers as big as 99999999 you can do it in code like I did

Pseudo code begins


miles[4] var byte ' lsb to msb

on input pulse, pulses=pulses+1

if pulses >= Pulsespermile
pulses = 0 ' start counting again till we reach pulses per mile

miles[0] = miles[0]+1
if miles[0] > 99 then
miles[0] =0
miles[1] = miles[1]+1
if miles[1] > 99 then
miles[1] = 0
miles[2] = miles[2]+1
if miles[2] > 99 then
miles[2] = 0
miles[3] = miles[3]+1
if miles[3] > 99 then
miles[3] = 0 ' roll over to all zero
endif
endif
endif
endif
endif



Now, displaying this is easy.


Num = miles[0] dig 1 ' first digit to display
digitpos = 0
gosub displaynum ' show the number

Num = miles[0] dig 0 ' 2nd digit to display
digitpos = 1
gosub displaynum ' show the number

Num = miles[1] dig 1 ' 3rd digit to display
digitpos = 2
gosub displaynum ' show the number

Num = miles[1] dig 0 ' 4th digit to display
digitpos = 3
gosub displaynum ' show the number

and so on

NullDevice
- 13th May 2010, 02:53
I'm trying to rid the world of 16F chips...

I'm with you, Charles, but is there a PIC18 that is nearly the same price as a PIC16F88? I'm doing a low cost consumer product right now where 40 cents makes a big difference. Until that time, that evil PIC16F architecture lives on.

Charles Linquis
- 13th May 2010, 03:31
In some cases,(like high-volume applications), the 16F series makes sense. But too often I see people that work hours (or tens of hours) longer to get something to work because they started out with an inadequate chip on a one-off project.

rmteo
- 13th May 2010, 04:12
I'm with you, Charles, but is there a PIC18 that is nearly the same price as a PIC16F88? I'm doing a low cost consumer product right now where 40 cents makes a big difference. Until that time, that evil PIC16F architecture lives on.
According to here PIC16F88 (http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010243) the lowest cost device is $2.20 - if you go here PIC18 Product Family (http://www.microchip.com/ParamChartSearch/chart.aspx?branchID=1004&mid=10&lang=en&pageId=74) and do a sort on ascending price, you will find about 45 PIC18's that cost less than a PIC16F88. That said, I use several competitive 32-bit devices that are about half that price.

Darrel Taylor
- 13th May 2010, 07:47
Not sure, but maybe you can just change 1-line.



'---[INT - interrupt handler]---------------------------------------------------
ToggleLED1:
cnt = cnt +1
cntb = cnt * 20 ; could be * 1000
meter = DIV32 f0
If meter = x Then
meter = 0
km = km + 1
cnt = 0
Endif
@ INT_RETURN
Depends on what f0 and x are.

BigWumpus
- 16th May 2010, 23:27
If you are looking for costs ... forget all this old 16F... or 18F...-devices.

Take new cheap dsPic33 or ...J... or ...K... -devices.
The new devices are very cheap, the old stuff is expensive !!!!

Bill Legge
- 17th May 2010, 02:51
Not an economic solution but great fun is the 'floating point co-processor' from Micromega. Costs about $20. the free IDE make developing the code a doddle.

Regards Bill Legge