my question is how do i convert my binary value to a decimal so i can work with it.
k
my question is how do i convert my binary value to a decimal so i can work with it.
k
Hi lerameur,
In your code piece here, first you are missing ENDIF. For now say it is there, then;
Your variables are all decimal already.
Also, say that Right = 5 and Left = 2.
Then,
IF Right > Left statement will be executed; then
Temp = Right - Left
(Temp = 3)
Temp = Temp/Right
(Temp = 3/5)
(Temp = 0)
Temp = Temp*254
(Temp = 0)
In this case, you will get TEMP as zero, because you will always be dividing a small number by a bigger number.
Also, if you run your code alone, it will not give you any errors.
Code:IF Right > Left THEN 'left and right are from sensor reading Temp =Right-Left Temp= Temp/Right Temp= Temp * 254 HPWM 1,255-temp,1000 HPWM 2,255,1000 ENDIF 'No errors !!
Thus, you should check the rest of your code. It seems that you have no problem with your IF statement.
-------------------------------
Last edited by sayzer; - 4th November 2006 at 16:22.
"If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte
ok but how do i get the 0.6 from 3/5
maybe (3/5)*254 ?
i do not want zero
also,
I removed these lines and it now compiles:
I thought I needed them...
'DEFINE CCP1_REG PORTC ‘ Hpwm 1 pin port, RIGHT
'DEFINE CCP1_BIT 2 ‘ Hpwm 1 pin bit
'DEFINE CCP2_REG PORTC ‘ Hpwm 2 pin port, LEFT
'DEFINE CCP2_BIT 1 ‘ Hpwm 2 pin bit
'DEFINE HPWM1_TIMER 1
'DEFINE HPWM2_TIMER 1
k
why not 30/5 ?
OR (or i'm right) 3//5?
There's a Huge difference between a apostroph ' and the other thing ‘'DEFINE CCP1_REG PORTC ‘ Hpwm 1 pin port, RIGHT
'DEFINE CCP1_BIT 2 ‘ Hpwm 1 pin bit
'DEFINE CCP2_REG PORTC ‘ Hpwm 2 pin port, LEFT
'DEFINE CCP2_BIT 1 ‘ Hpwm 2 pin bit
Last edited by mister_e; - 4th November 2006 at 18:25.
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
Floating point is not supported by PBP lerameur. Thus you can not use parenthesis; still zero.
There are still ways to go around it though, take mister_e's example.
Multiplying by 10 could work but
if the difference is too big then need to multiply by 100.
and then if the difference is very big, word size variable may be, then multiply by 1000 shall work.
Ex:
Right = 240 and Left = 235;
then Temp=5.
Now, 5/240 or 50/240 will not work.
You will need to multiply by 100 and have 500/240.
Thus you need to multiply temp by 10 or 100 or 1000 based on your values.
-----------------------------
-------------------------------
"If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte
Bookmarks