Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to deal with float values..?

Status
Not open for further replies.

Nikunj Tanna

Advanced Member level 4
Joined
Dec 8, 2009
Messages
115
Helped
23
Reputation
46
Reaction score
15
Trophy points
1,298
Location
Ahmedabad, Gujarat, India
Activity points
1,985
Hello all,

I am working on 16 bit adc ADS 7825, I've got output of it which is in form of 2's complement. I've also converted that hex value into decimal, now I want to display the voltage value like 2.45xx, 3.4267 etc., on six digit 7 segment.

So, I need to multiply the decimal value with 5V / 65536(16 bit). So I got float value to multiplied with the decimal. Now how to handle this float value calculation and how to display the resultant float value on 7 segment..?

I am using codevision avr and the controller is ATMEGA 128.

The code is given below::

#include <stdio.h>
#include <stdlib.h>

#define CLK PORTA.0
#define DATA PORTA.2
#define LATCH PORTA.1
#define A1 PORTA.3
#define A0 PORTA.4
#define byte PORTA.5
#define rc PORTA.6
#define busy PORTA.7

unsigned char digit[5];
void main(void)
{
unsigned char data,data2,data3,data4,i,j;
unsigned int final=0,fi2=0;

while(1)
{

rc = 1;
A1 = 0;
A0 = 0;
PORTG &= 0x00; // portg.2 (contc) = 0
byte = 0;
rc = 0;
delay_us(4);
rc = 1;
while(busy == 0);
data = PINC;
byte = 1;
for(i=0;i<1;i++) for(j=0;j<2;j++);
data2 = PINC;

data3 = ~ data;
data4 = ~ data2;

final = (data3<<8) + data4 + 1; // 2's complement

fi2=hex2dec(final); // getting decimal value



}
}

int hex2dec(unsigned int lnum)
{
unsigned char i=0;
unsigned int deci;
while(lnum > 10)
{
digit = lnum % 0x0a;
lnum = lnum / 0x0a;
i++;
}

deci = atoi (digit);
return deci;
}


NIKS
 

Hi

In order to display the A2D value on a 7 segment display you will need to convert the decimal number into plain char's separate them into segment and then add the decimal point

for example :you want to display : 6.55V

1) set it to mV reading :655
2)separate and convert to to ASCII( or to 7 seg data ) char : 0x36,0x35,0x35
3)send each char to seven Seg display
4)Set on the decimal point

All the best

Bobi

The microcontroller specialist
 

Instead of multiplying by 5/65536, multiply by 5000/65536. So u know that a result of 1000 means 1. Just put the point btw 1 and 0. Enjoy friend.
 

Hello all,

There is one more problem arises, The function hex2dec doesn't give output, when I run that code, it gives nothing... Can anyone tell me what's wrong with that funciton??

NIKS
 

There's a lot of confusion in your code. hex2dec doesn't work because you apply atoi() on numeric values, but it only works
for null terminated ASCII strings. Furthermore, I don't see the purpose of applying atoi(). The digit array contains already
the numeric values, that can be output to your display.
 

Hi,

I tried the code without atoi, you are right it works and gives the numeric value..
The new function for testing is like this..

void hex2dec(unsigned int lnum)
{
unsigned char i=0;
unsigned int deci;
while(lnum > 10)
{
digi = lnum % 0x0a;
lnum = lnum / 0x0a;
uart_digit(digi); // Display value for uart
i++;
}
delay_ms(500);
}

I am getting decimal value in uart..But i don't know exactly that how to go ahead and display the output on 7-segment..

I've to use this array and have to do some multiplications and then display it to 7 segment. But I am not able to get this value out of this function..

NIKS
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top