Help with decimals/RPM

JordanR

New Member
I am an A2 student that is making a rolling road for a Greenpower race car.

I currently have a system that allows me to count RPM using a opto-isolator but need to change RPM into meters per second. The formula I have is:

V = radius in meters*RPM*0.10472

The problem I am facing is trying to find a way to implement the 0.10472 as I do not know how to make an accurate decimal of this length.

I am using a 18M2 chip
The radius of the wheel is 0.26m
The RPM range is 0-504 which is equivalent to 0-30mph
A preference would be then to output m/s in mph. To convert to mph I have to do m/s*2.23694 (another decimal!)

Solutions:
Currently I have tried to use the b0 variables to produce the decimal however this doesn't work because I am getting an output of 0.165;

b0=104
b1=1000
b2=b0/b1
b3=b0*1000/b1//1000
serout b.0,n2400,(254,1,254,128,#b2,".",#b3)
end

Another option I have is to use the uM-FPU V2 chip which I have looked at but have found it is a bit out of my league.

Thanks in advance,

JordanR
 
Last edited:

hippy

Technical Support
Staff member
Welcome to the PICAXE forum.

y = x * 0.n

y = x * ( ( 0.n * 65536 ) / 65536 )

y = x ** ( 0.n * 65536 )

So if the 0.n is 0.10472, that times 65536 is 6863, so -

y = x ** 6863

That will give an integer result. For one decimal point it would notionally be -

y = x ** 68629

However that 68629 value is too large, but one could do -

y = x * 2 ** 34315
 

AllyCat

Senior Member
Hi,

Welcome to the forum. Firstly, you must use word values (w0, w1, etc.) for calculations like this. Note that b1 = 1000 actually sets a value of b1 = 232.

Scaling (i.e. multiplication) by a "known constant" of less than 1 (e.g. your 0.10472) can be easily done using the ** operator. The ** operator multiplies two interger values and then divides by 65536 (which is largest number that can be stored in a word, + 1).

Using a pocket calculator work out 0.10472 * 65536 (= 6863). Then your program can multiply the value in (say) w1 by 0.10472 by using:

Let w2 = w1 ** 6863 .

Cheers, Alan.
 

marks

Senior Member
Hi jordanR
sounds like a good project to be involved in!
I must admit I didn't understand your figures so worked it out from the circumference 1.63362 metres per revolution
the end result seems to match !
0 to 504 or
0 to 49.400 km/h or
0 to 13.722 m/s or your formula's the same 0.26 x 504 x 0.10472
0 to 30.695 mph

so
504 x 62 x 64377 / 65536 = 30695

W0 = W0 *62 **64377
 

JordanR

New Member
Thank you everyone that has replied as this was a great help, however I am now stuck on how to display this variable/ value.

The code I have made is;

wait 1

do
w2 = w1 ** 6863 (0.10472)
w4 = w3 ** 17040 (0.26)
w5 = w2 * w4 * 504
serout c.3,n2400,(254,1,254,128,#w5)
loop

The answer I am getting on a calculator is 13.7225088 but the value on my OLED is 0. Is there any idea why this is happening? I am thinking because is such a long number that it exceeds the largest value limit.
For this project I only need to output either a whole number that is rounded (e.g. 14) or to 0.1 decimal place (e.g. 13.7)
 

hippy

Technical Support
Staff member
w2 = w1 ** 6863 (0.10472)
w4 = w3 ** 17040 (0.26)
w5 = w2 * w4 * 504
w1 and w3 are always zero so the result will be too. Try ...


Code:
Symbol rpm = w0
Symbol vel = w1

Do
  rpm = 504
  vel = rpm ** 1784
  SerTxd( #vel, CR, LF )
Loop
That 1784 = 0.26 * 0.10472 * 65536

For one decimal place ...

Code:
Symbol rpm = w0
Symbol vel = w1

Symbol n1  = b11
Symbol n2  = b12
Symbol n3  = b13
Symbol n4  = b14
Symbol n5  = b15

Do
  rpm = 504
  vel = rpm ** 17844
  BinToAscii vel, n5,n4,n3,n2,n1
  SerTxd( n5,n4,n3,n2,".",n1, CR, LF )
Loop
 
Last edited:

AllyCat

Senior Member
Hi,

Presumably the figures in brackets are the scaling factors for information. You should separate them off with a "REMark" symbol (; or ') to prevent the Progarm Editor giving Syntax Errors.

We don't know what values you have for w1 and w3, but if w1 < 9 or w3 < 4 then the result will indeed be zero. For testing it's useful to include a SERTXD(#w1," ",#w3,cr,lf) or a DEBUG command to report the values on the PE terminal.

If w1 and w3 are large, say > 1,000, (which can be beneficiaL to give good resolution or accuracy of the result) then there is a risk that w5 = w2 * w4 * 504 will overflow the word variable and produce an incorrect result. There are various "tricks" to use with PICaxe to avoid this and/or to give better rounding (up) of small values.

Cheers, Alan.
 

BESQUEUT

Senior Member
V = radius in meters*RPM*0.10472

The problem I am facing is trying to find a way to implement the 0.10472 as I do not know how to make an accurate decimal of this length.

I am using a 18M2 chip
The radius of the wheel is 0.26m
The RPM range is 0-504 which is equivalent to 0-30mph
A preference would be then to output m/s in mph. To convert to mph I have to do m/s*2.23694 (another decimal!)
The radius of the wheel is only known with 2 significatives digits.
So, regardless of your calculation method, yous will never have a result with more than 2 significatives digits.

Derived from Hippy proposal :

Code:
[color=Blue]Symbol [/color][color=Purple]rpm [/color][color=DarkCyan]= [/color][color=Purple]w0[/color]
[color=Blue]Symbol [/color][color=Purple]vel [/color][color=DarkCyan]= [/color][color=Purple]w1[/color]

[color=Blue]Symbol [/color][color=Purple]n1  [/color][color=DarkCyan]= [/color][color=Purple]b11[/color]
[color=Blue]Symbol [/color][color=Purple]n2  [/color][color=DarkCyan]= [/color][color=Purple]b12[/color]
[color=Blue]Symbol [/color][color=Purple]n3  [/color][color=DarkCyan]= [/color][color=Purple]b13[/color]
[color=Blue]Symbol [/color][color=Purple]n4  [/color][color=DarkCyan]= [/color][color=Purple]b14[/color]
[color=Blue]Symbol [/color][color=Purple]n5  [/color][color=DarkCyan]= [/color][color=Purple]b15[/color]


[color=Blue]for [/color][color=Purple]rpm [/color][color=DarkCyan]=[/color][color=Navy]0 [/color][color=Blue]to  [/color][color=Navy]504 [/color][color=Blue]step [/color][color=Navy]20
  [/color][color=Purple]vel [/color][color=DarkCyan]= [/color][color=Purple]rpm [/color][color=DarkCyan]*[/color][color=Navy]5 [/color][color=DarkCyan]+[/color][color=Navy]1[/color][color=DarkCyan]** [/color][color=Navy]35687
  [/color][color=Blue]BinToAscii [/color][color=Purple]vel[/color][color=Black], [/color][color=Purple]n5[/color][color=Black],[/color][color=Purple]n4[/color][color=Black],[/color][color=Purple]n3[/color][color=Black],[/color][color=Purple]n2[/color][color=Black],[/color][color=Purple]n1
  [/color][color=Blue]SerTxd( [/color][color=Black]#[/color][color=Purple]rpm[/color][color=Black],[/color][color=Red]" " [/color][color=Black],[/color][color=Purple]n4[/color][color=Black],[/color][color=Purple]n3[/color][color=Black],[/color][color=Red]"."[/color][color=Black],[/color][color=Purple]n2[/color][color=Black],[/color][color=Purple]n1[/color][color=Black], [/color][color=Blue]CR[/color][color=Black], [/color][color=Blue]LF )
next [/color][color=Purple]RPM[/color]
Excel calculation : V=RPM*0,26*0,10472
Code:
RPM	V
0	0,00
20	0,54
40	1,09
60	1,63
80	2,18
100	2,72
120	3,27
140	3,81
160	4,36
180	4,90
200	5,45
220	5,99
240	6,53
260	7,08
280	7,62
300	8,17
320	8,71
340	9,26
360	9,80
380	10,35
400	10,89
420	11,44
440	11,98
460	12,52
480	13,07
500	13,61
520	14,16
 
Last edited:
Top