View previous topic :: View next topic |
Author |
Message |
avarachan
Joined: 24 Sep 2009 Posts: 3 Location: Buffalo, NY
|
How to Print binary as decimal fraction |
Posted: Thu Sep 24, 2009 6:49 pm |
|
|
Hi all,
I'm working on PIC18f2620 + CS5463 (power monitor). I saw some posts regarding CS5463 spi. In CS5463 registers, some values are 0<Vrms(for eg.)<1. These are 24 bit registers. I can read these values well and good into the processor. I'm using pic18f2620 with MPLAB IDE +CCS version 4.3.
Is there a way I can use some printf method to get the decimal fraction? or some usable format? Or should I do bit by bit 2^i thing?
To be more clear, lets say I read 0xC00000 from Vrms register. This is 0b110000000000000000000000. I need to convert it to 0.75.
Appreciate any help in advance.
Avarachan |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Sep 24, 2009 7:19 pm |
|
|
The simple way, conceptually, is just to do a division. The program
below has this output:
Code: |
#include <18F452.h>
#fuses XT,NOWDT,PUT,BROWNOUT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
//======================================
void main(void)
{
int32 value;
float result;
value = 0xC00000;
result = (float)value / 0x1000000;
printf("%4.2f \r", result);
while(1);
}
|
I'm assuming that your value is an unsigned number. |
|
|
avarachan
Joined: 24 Sep 2009 Posts: 3 Location: Buffalo, NY
|
thanks |
Posted: Fri Sep 25, 2009 9:49 am |
|
|
Thank you. I think i will use simple division. I was at a loss as the various registers have different binary point locations. Thanks, PCMProgrammer! |
|
|
dsabatino
Joined: 29 Jan 2010 Posts: 2
|
CS5463 SPI help |
Posted: Tue Feb 02, 2010 1:24 am |
|
|
Hello avarachan,
I am attempting to communicate with the CS5463 but I am having some difficulties getting my microcontroller to interface over the SPI. Could you please post your code so that I may see your working example? I am using the Atmega32 but I'm sure I would be able to port the code as needed.
Thank you very much! |
|
|
Edson
Joined: 10 Mar 2011 Posts: 1 Location: Portugal
|
Re: How to Print binary as decimal fraction |
Posted: Fri Mar 11, 2011 3:18 pm |
|
|
avarachan wrote: | Hi all,
I'm working on PIC18f2620 + CS5463 (power monitor). I saw some posts regarding CS5463 spi. In CS5463 registers, some values are 0<Vrms(for eg.)<1. These are 24 bit registers. I can read these values well and good into the processor. I'm using pic18f2620 with MPLAB IDE +CCS version 4.3.
Is there a way I can use some printf method to get the decimal fraction? or some usable format? Or should I do bit by bit 2^i thing?
To be more clear, lets say I read 0xC00000 from Vrms register. This is 0b110000000000000000000000. I need to convert it to 0.75.
Appreciate any help in advance.
Avarachan
|
Hi Avarachant
I'm not reading anything at all on CS5463. Is there any way you can send me the routine that you're using to initialize the CS5463? _________________ Edson Teixeira |
|
|
|