single point precision + HART

Go To Last Post
16 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi everyone,

 

I'm trying to send data in HART protocol. The value should be transmitted in single point precision structure. 

My main question is if I have a float variable and I assign it into 4 byte of chars, is it right thing to do? or I should have a function to convert it into binary code and then transmit it?

I'm using codevision and micro is Xmega128A1u.

 

Thanks for your help

Best Regards

In the end it doesn't even matter ...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If it were me, I would convert it to ASCII text. That is "123.4". One of the format() functions will probably do it for you - not sure what codevision provides but its in avr-gcc.

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

tzanti wrote:
The value should be transmitted in single point precision structure

So what does that actually mean?

Is it the HART specification which mandates that?

If so, then surely it defines that format?

 

 I have a float variable and I assign it into 4 byte of chars, is it right thing to do? or I should have a function to convert it into binary code and then transmit it?

You do whatever fulfils the requirement that you stated - "single point precision structure"

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

For example in HART protocol when you want to send your primary value to the master specification says that send 4-bytes (say 0-3) in "Float" format, according to IEEE 754 standard. 

So my question is that how should I do that.

Let's say I have a float variable "PV", which equals to 11.57 now I want to send this "PV" in the 4-byte format. Is there any pre-defined function to do so or I should make a function for myself to do such a transform

and vice-versa.

 

Thanks. 

In the end it doesn't even matter ...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

tzanti wrote:
how should I do that.

It seems pretty clear - where is the problem?

 

If you don't know what "IEEE 754 standard" is, then look it up!

 

Google is your friend.

 

You might also ask yourself whether your AVR toolchain (CodeVisionAVR, I think you said) might already be using the IEEE 754 format ...

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

AFAIK all AVR C compilers already hold 32 bit float variables in IEEE754

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes I looked it up, and I know how it works.

I didn't find a straight forward way to do it. So I was looking for a function  that can do this conversion for me. 

I couldn't find such function in codevision-AVR, that's why I'm asking here to see if anybody saw such a thing that I couldn't find in my searches.

In the end it doesn't even matter ...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Is there anything special to do so or just describing a variable as float is enough?

I need to send it as 4 bytes how should I do that allocation? 

In the end it doesn't even matter ...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Go on!  It's just a set of 4 bytes - isn't it?

 

You transmit the first one, then the second one, then the third one, and finally the fourth one.

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It seems float is already stored in 4 bytes in the memory, so problem is solved.

Thanks for you answers.

In the end it doesn't even matter ...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hart protocol seems to build a packet. And your data is contained in the packet Data field.
It looks as if the Data field can contain any binary data. So you can put the 32-bit float as four 8-bit chars in the Data field.
You would build the packet in SRAM. Then transmit the packet by whichever method you like.
.
I would write a function to build the packet. Return the packet size N..
And a function to transmit the packet. e.g. send N bytes
.
This should be very simple to do. If you are using the UART, the second function would use putchar()
.
David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

tzanti wrote:
 float is already stored in 4 bytes

and not just in any 4 bytes, but specifically in the IEEE754 FORMAT - as required.

 

https://en.wikipedia.org/wiki/IEEE_754

 

so problem is solved.

There never was any problem in the first place!

 

wink

 

Please mark the thread as solved: http://www.avrfreaks.net/comment...

 

EDIT

 

Wikipedia link, for reference.

 

EDIT 2

 

The IEEE 754 Single-precision floating-point format, specifically:

 

https://en.wikipedia.org/wiki/Single-precision_floating-point_format

 

Float example.svg

Last Edited: Thu. Nov 2, 2017 - 11:14 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:
There never was any problem in the first place!
Endianism ?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

david.prentice wrote:
you can put the 32-bit float as four 8-bit chars in the Data field.

The HART Application Guide specifically states,

IEEE 754 floating point format (32 bits) with engineering units

https://www.fieldcommgroup.org/sites/default/files/technologies/hart/ApplicationGuide_r7.1.pdf  - see page 188

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
Endianism ?

hasn't been addressed yet ...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

For anyone who had the same problem, I should say that float is stored in 4 byte and in order to convert it into 4 byte of chars you should do the casting something like this:

  send_dataR[k++]=*((unsigned char *)prime+3);
  send_dataR[k++]=*((unsigned char *)prime+2);
  send_dataR[k++]=*((unsigned char *)prime+1);
  send_dataR[k++]=*((unsigned char *)prime);

where prime is a float pointer and send_dataR is a char array. 

In the end it doesn't even matter ...