Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Embedded C
 
Test_time = Test_time/10;
jump_height = ((98*(Test_time*Test_time))/ 80);
    LCD0 = jump_height/1000;
    LCD1 = (jump_height/100)%10;
    LCD2 = (jump_height/10)%10;
    LCD3 = jump_height%10;
 
I don't really want to divide test_time by 10 as this affects the resolution. The problem is the jump equation as jump_height is an unsigned int and the calculation doesn't fit into it.
 
this is for an embedded C application not PC.
 
thanks,
Posted 24-Nov-10 4:41am
Edited 30-Nov-10 4:54am
v5
Comments
ManfredRBihy at 24-Nov-10 9:45am
   
Small re-edit adjusted end value to 50 giving 500ms. (The other way round would have meant to much work for me (I mean if I had adjusted the elapsed time to 50000ms)) :-)
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

I'm not sure I agree with your first sentence; if the integer increments once every 10ms then the value of 5000 should mean 50,000ms.
 
Breaking your equation down:
timesquared = time ^ 2 (assuming you mean time squared?)
interimtime = timesquared * 9.8
h = interimtime / 8
 
so if time = 500
timesquared = 250,000
interimtime = 2,450,000
h = 306,250
 
Is h now the height in micrometers (i.e. 0.3 metres)?
 
Assuming that is correct then just divide by 1000000 and put to the display.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

your right about the fist sentence. a count of 50 would equal 500ms
 
the problem is that the height is an unsigned int and not sure the calculated values fit into the data type.
 
the display takes 4 arguements namely LCD0, 1 2 and 3.
 
so to display you must Display_LCD(LCD0, LCD1, LCD2, LCD3)
 
I have thought about calculating 2 heights h_m and h_cm and then displaying but no luck as yet.
 
LCD0 = m (tens)
LCD1 = m (units)
LCD2 = cm (tens)
LCD3 = cm (units)
 
thanks
  Permalink  
Comments
Richard MacCutchan at 24-Nov-10 12:46pm
   
Assuming that you get your height value in centimetres, then calculating the values for LCD0/1/2/3 should not be too difficult; a small loop taking the "modulo 10" value each time.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 365
1 Sergey Alexandrovich Kryukov 319
2 CPallini 275
3 DamithSL 214
4 Maciej Los 185
0 OriginalGriff 5,455
1 DamithSL 4,457
2 Maciej Los 3,885
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,115


Advertise | Privacy | Mobile
Web02 | 2.8.141216.1 | Last Updated 30 Nov 2010
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100