Sign in to follow this  
Rodney

Byte conversions

Recommended Posts

Hi

please see attached

excuse my ignorance on this topic as a non programmer newbie this is an area I know little about

I need to access the the bytes (I think) of the registers to use the data

I can return the data readinputU16 but don't know what to do with it.....

I have read the manual section 4.12.10 on byte conversions but I'm a little lost

for hex register 3201 (Decimal 12801) if I wanted to access the value in D9 (load over current) (I am assuming it will be either 1 or 0) what is the expression to do this?

similarly D3-D2(charging status) how do I access the value (2 bytes?) - what is the expression for this?

Regards

Rodney

 

 

  

 

Mppt_Channels2.PNG

Share this post


Link to post
Share on other sites

For a bit, you can use TestBit().  For a group of bits (say D7-D4 of A15), you would have to mask and shift:  (value >> 4) & 0x07.  This is basic bitwise boolean math that is covered in basic old-school computer science texts if you want to read more.

 

Share this post


Link to post
Share on other sites

Hi

Sorry for the late reply but other issues on my project have taken priority..... 

Can you confirm if I have understood you reply

if I named A15 above Batt_Status and I want to return  D8

then the syntax is

TestBit(Batt_Status[0],8)

D7-D4

(Batt_Status[0]>>4) & 0x07

and

D3-D0

(Batt_Status[0]>>4) & 0x03

if I named A16 CES and I wanted the charging status (D3-D2)

(CES[0]>>2) & 0x03 

Thank you 

Rodney

 

 

 

Share this post


Link to post
Share on other sites

sorry one final syntax to check

if I wanted A16  D15-D14

would it be

(CES[0]>>2) & 0x0F

thanks

 

 

 

Share this post


Link to post
Share on other sites

Most no. You have the wrong hex values.  You have to think in binary, and might want to use binary notation instead::

D7-D4

(Batt_Status[0]>>4) & 0b1111

and

D3-D0

Batt_Status[0] & 0b1111

if I named A16 CES and I wanted the charging status (D3-D2)

(CES[0]>>2) & 0b0011 

if I wanted A16  D15-D14

would it be

(CES[0]>>14) & 0b11

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this