Go Down

Topic: int and unsigned int (Read 3 times) previous topic - next topic

Pavilion1984

Ok thanks AWOL but can you understand what am trying to achieve here. I will try and get a shift register this week and then see how wrong my code is when it don't display the results i was hoping for because my code is bound to be wrong.

Nick Gammon


below is what i think i would see on a 16bit shift register when i buy one.

Code: [Select]
1000rpm = 1000000000000001
2000rpm = 1100000000000011
3000rpm = 1110000000000111
4000rpm = 1111000000001111
5000rpm = 1111100000011111
6000rpm = 1111110000111111
7000rpm = 1111111001111111
8000rpm = 1111111111111111


Does that explain everything now.


Not really. What's that got to do with RPM?

Pavilion1984

That's how I want to show the rpm value on a row of LEDs as part of a digital dash for my track car. A good example would be the f1 steering wheel then you might get the idea. I think the original question has been missed here now.

Nick Gammon

Oh, OK, but the engine won't generate negative RPM will it?

As for the original question, the writers of libraries are trying to cram stuff into 32 Kb of program memory (even less on the earlier models and other chips). Getting the number of digits right, for negative binary numbers, which would increase program size, but benefit practically no-one, was probably not a high priority for them.

Pavilion1984

#24
Oct 09, 2012, 08:58 am Last Edit: Oct 09, 2012, 09:00 am by Pavilion1984 Reason: 1
Ok thanks Nick. No it wont. What am doing is getting the data over the OBD port on the vehicle and storing the value in a unsigned int as a DEC number between 0 and 8000 and that works great. So what am trying to do here is take that number and turn on some LED's (depending on what the RPM value is) over the SPI port to a 16bit shift register. Sorry if i have not really explaind myself properly here but i will try and explain as best as i can again.

I will have 16 LED's in a row (1 = LED on and 0 = LED off).
For example my RPM value is 5000. Out of 16 LED's i want to turn on 5 LED's on the left and 5 LED's on the right. So the efect i want on my LED's is below
1111100000011111 <- (binary number)/(63519, dec number) 5000RPM
1111110000111111 <- (binary number)/(64575, dec number) 6000RPM, turn on 6 LED's either side
1111111001111111 <- (binary number)/(65151, dec number) 7000RPM, turn on 7 LED's either side

So i hope you can see what effect am trying to create (LED's light up from the left and right at the same time and meet up in the middle at max RPM).

Thats why am using binary (bitshift)
Code: [Select]
Display_RPM = ~((1 << (16 - temp))-1) | ((1 << temp)-1);
to create that efect everytime i read a new RPM value then send the effect out to the shift register. I was going to use a lookup table for patterns but i was told a better way would be to use bitshift and if only 1 line of code.

Hope that makes sense, if not then slap me with a fish lol. I will post my project on here when i think it's ready to share.

Go Up