HX711 hal Modul

More
22 May 2015 15:49 #58933 by fupeama
HX711 hal Modul was created by fupeama
HI,
Here is hal modul for communication with ADC HX711. I want to use it for setup tension on cutting wire through PID and servo motor.
Martin
component hx711 "Interface";

description """Crude Interface.  Reads analog data from HX711.""";

pin out bit SCK "SCK pin out";
pin in  bit DT  "DT input";
pin out  float output "output value";
pin in bit enable "Enable pin";
pin in bit reset "Reset pin (set channel A Gain 128)" ;
pin in bit select "select channel 0=ch.A gain 128, 1=ch.B gain 32";

function _ nofp;
license "GPLv2 or greater";
author "MK";

variable int ByteState = 0;
variable int BitState = 0;
variable int bnum = 0;
variable u32 TXByte;
variable int oldDT;
variable int waitcount = 0;
variable int chselect;

;;

enum Byte_state
    {
	eIdle               = 0,
	eWait               = 1,
	eRead		    = 2,
	eReset              = 3
    };
enum Bit_State
    {
	eIdleBit          = 0,
	eSCKLow           = 1,
	eSCKHigh          = 2,
	eResetBit         = 3
    };

FUNCTION(_)
{
	if (enable) {
		if (reset){
			ByteState = eReset;
		}
		chselect = (select==1) ? 26 : 25;
		
		// bytes
		switch (ByteState) {
		case eReset :
			BitState = eResetBit;
			break;
		case eIdle :
			BitState = eIdleBit;
			if (!DT && oldDT){
				ByteState = eRead;
				BitState = eSCKHigh;
				bnum = 0;
			TXByte = 0;
			}
		break;
		case eRead :
			if (BitState ==  eSCKHigh) {
			   if (bnum < 24){
				TXByte = (DT==1) ? (1 | TXByte << 1) : (TXByte << 1);
			   }
			bnum++;
			}
			if (bnum == chselect){
				output = TXByte;
				bnum = 0;
				ByteState = eIdle;
				BitState = eIdleBit;
			}
			
		break;
		default :
            		ByteState = eIdle;

                }
		// bits
                switch (BitState) {
                case eResetBit :
                        SCK=1;
                        waitcount++;
                        if (waitcount>=100) {
                                waitcount = 0;
                                BitState = eIdleBit;
				ByteState = eIdle;
			}
                break;
                case eIdleBit:
			SCK = 0;
		break;
		case eSCKLow :
			SCK = 1;
			BitState = eSCKHigh;
		break;
		case eSCKHigh :
			SCK = 0;
			BitState = eSCKLow;
		break;
		default :
		        BitState = eIdleBit;

                break;
                }



        }
	oldDT = DT;
}

Please Log in or Create an account to join the conversation.

More
22 May 2015 15:50 - 22 May 2015 15:53 #58934 by fupeama
Replied by fupeama on topic HX711 hal Modul
And example config for parport. B)

File Attachment:

File Name: hx711.zip
File Size:3 KB
Attachments:
Last edit: 22 May 2015 15:53 by fupeama.

Please Log in or Create an account to join the conversation.

More
22 May 2015 19:45 #58938 by andypugh
Replied by andypugh on topic HX711 hal Modul
LinuxCNC is rather short of Analogue input options, especially for the parallel port.
You should at the very least add this to the Contributed Components on the Wiki and possibly consider getting it included in the distribution.

Please Log in or Create an account to join the conversation.

More
22 May 2015 20:53 #58939 by fupeama
Replied by fupeama on topic HX711 hal Modul
I tried it, but page is read only.
M

Please Log in or Create an account to join the conversation.

More
22 May 2015 21:11 #58940 by andypugh
Replied by andypugh on topic HX711 hal Modul

I tried it, but page is read only.
M


That's an anti-spam thing. If you look at the bottom of any page there is a link that tells you how to log in to change things.

The Penguin is called Chips.

Please Log in or Create an account to join the conversation.

More
22 May 2015 21:13 - 22 May 2015 21:16 #58941 by andypugh
Replied by andypugh on topic HX711 hal Modul
Actually, don't bother.
Seb has agreed that this ought to be added to the LinuxCNC distribution. I will push it tonight.

[Edit}
Actually, can you add a bit more to the description, just to make the auto-generated manual page a bit clearer, and change the tabs to 4 x spaces so that it matches
www.linuxcnc.org/docs/html/code/Style_Guide.html
Last edit: 22 May 2015 21:16 by andypugh.

Please Log in or Create an account to join the conversation.

More
22 May 2015 21:22 #58942 by andypugh

Please Log in or Create an account to join the conversation.

More
25 May 2015 15:49 - 25 May 2015 19:50 #58999 by fupeama
Replied by fupeama on topic HX711 hal Modul
HI,
I tried add some description and change variable u32 to unsigned.
here is new hx711.comp

Martin
component hx711 "Interface for read HX711";

description
"""Crude Interface.  Reads analog data from HX711.
 Modul must run on BASE-THREAD faster than 45000ns
 
 Example config
 loadrt hx711 
 addf hx711.0 base-thread
 net DT hx711.0.DT parport.0.pin-10-in
 net SCK hx711.0.SCK parport.0.pin-09-out
 

""";

pin out bit SCK "Serial Clock Input ";
pin in  bit DT  "Serial Data Output";
pin out  unsigned output "Output value";
pin in bit enable = TRUE "Enable read from hx711, default value = TRUE ";
pin in bit reset "Reset pin and Power Down (set channel A and Gain 128 for next read) if reset=1, hx711 is in power down mode" ;
pin in bit select "Select channel 0=ch.A gain 128, 1=ch.B gain 32";

function _ nofp;
license "GPL"; // indicates GPL v2 or later
author "fupeama";

variable int ByteState = 0;
variable int BitState = 0;
variable int bnum = 0;
variable int oldDT;
variable int waitcount = 0;
variable unsigned TXByte;
variable int chselect;

;;

enum Byte_state
    {
	eIdle		= 0,
	eWait		= 1,
	eRead		= 2,
	eReset		= 3
    };
enum Bit_State
    {
	eIdleBit		= 0,
	eSCKLow			= 1,
	eSCKHigh		= 2,
	eResetBit		= 3
    };

FUNCTION(_)
{
	if (enable) {
		if (reset){
			ByteState = eReset;
		}
		chselect = (select==1) ? 26 : 25;
		// bytes
		switch (ByteState) {
		case eReset :
			BitState = eResetBit;
			break;
		case eIdle :
			BitState = eIdleBit;
			if (!DT && oldDT){
				ByteState = eRead;
				BitState = eSCKHigh;
				bnum = 0;
			TXByte = 0;
			}
		break;
		case eRead :
			if (BitState ==  eSCKHigh) {
			   if (bnum < 24){
				TXByte = (DT==1) ? (1 | TXByte << 1) : (TXByte << 1);
			   }
			bnum++;
			}
			if (bnum == chselect){
				output = TXByte;
				bnum = 0;
				ByteState = eIdle;
				BitState = eIdleBit;
			}
			
		break;
		default :
			ByteState = eIdle;
		}
		// bits
		switch (BitState) {
		case eResetBit :
			SCK=1;
			waitcount++;
			if (waitcount>=10) {
				waitcount = 0;
				BitState = eIdleBit;
				ByteState = eIdle;
			}
		break;
		case eIdleBit:
			SCK = 0;
		break;
		case eSCKLow :
			SCK = 1;
			BitState = eSCKHigh;
		break;
		case eSCKHigh :
			SCK = 0;
			BitState = eSCKLow;
		break;
		default :
			BitState = eIdleBit;
		}
	}
	oldDT = DT;
}

and some picture




Attachments:
Last edit: 25 May 2015 19:50 by fupeama. Reason: change float to unsigned in output value

Please Log in or Create an account to join the conversation.

More
25 May 2015 19:15 #59007 by andypugh
Replied by andypugh on topic HX711 hal Modul
I think one of the points that Chris was making is that the comp has
function _ nofp ;

But the output value is a float, so assigning a value to is it a floating-point operation.
However, as its value is set directly from an unsigned (TBbyte) it only ever holds integer data, so should probably also be an integer.
(Probably a signed integer, just because those display better in halcmd)

Please Log in or Create an account to join the conversation.

More
25 May 2015 19:53 #59009 by fupeama
Replied by fupeama on topic HX711 hal Modul
ok,
I changed float to unsigned for output value.
But now I need convert u32 to float for using limit3 as input from hx711.
Martin

Please Log in or Create an account to join the conversation.

Time to create page: 0.260 seconds
Powered by Kunena Forum