View previous topic :: View next topic |
Author |
Message |
rosiley
Joined: 29 May 2014 Posts: 18 Location: Brasil
|
HX711 with 16F887 problem |
Posted: Sat Feb 03, 2018 10:19 am |
|
|
Hello guys,
I'm using an HX711 with a 16F887 to read a torque cell where it must report the values in both directions, time and counterclockwise. I searched the net and found nothing that could help me to get out of scratch, like drivers for hx711 and even how to start the code to read the sensor. All this information should be sent to the pc and also to an LCD display and another 7 segment display. This part I already know how to do and I already have the circuit ready and working. The problem is in the hx711 how to make it work. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19513
|
|
Posted: Sat Feb 03, 2018 1:04 pm |
|
|
It's just SPI mode 1.
The only special thing is the data in pin to the PIC has to be monitored before he transfer to know that data is ready.
You read the pin which you have already setup with #USE SPI as the data input, and when it drops, just do a three byte SPI read. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9226 Location: Greensville,Ontario
|
|
Posted: Sat Feb 03, 2018 1:32 pm |
|
|
Best place to start is the mfr's website and download the datasheet. It'll have the register tables and commands. SPI is of course easy with the CCS compiler,so it's just a matter of sending the correct 'setup parameters' for whatever loadcell you're using.
I'd start with a simple program to confirm you've got the hardware correct, then test for various inputs.
When posting questions like this you should supply a link to the appropriate datasheet. For instance I have no idea whether this is a 5v device, 3 v device or programmable ?
Jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19513
|
|
Posted: Sat Feb 03, 2018 2:13 pm |
|
|
I've used the chip.
No registers to set up.
You just wait for the data line to drop, and then read three bytes. These give the 24bit data the chip returns. The line goes high when you finish, and then drops again when the chip has another reading ready. It really is a 'doddle' to do. |
|
|
MikeW
Joined: 15 Sep 2003 Posts: 184 Location: Warrington UK
|
|
Posted: Sat Feb 03, 2018 2:27 pm |
|
|
I used the HX711 without any problems
cant remember if I used the SPI though
// SPI port
#pin_select SDO1=PIN_B10
#pin_select SDI1=PIN_B11
#pin_select SCK1OUT=PIN_B13
#pin_select SS1OUT=PIN_B12
#use spi( SPI1, FORCE_HW, BITS=8, stream=SPI_STREAM)
#define HX711_CLK pin_B3
#define HX711_DAT pin_B2
unsigned int32 Get_Load_Cell_Values()
{
unsigned int32 Count;
unsigned char i;
signed int32 Count_C;
Output_low(HX711_CLK);
Count=0;
while(Input(HX711_DAT));
for (i=0;i<24;i++)
{
Output_High(HX711_CLK);
Count=Count<<1;
Output_low(HX711_CLK);
if(Input(HX711_DAT)) Count++;
}
Output_High(HX711_CLK);
Count=Count^0x800000;
Output_Low(HX711_CLK);
return(Count);
} // end of function |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9226 Location: Greensville,Ontario
|
|
Posted: Sat Feb 03, 2018 2:32 pm |
|
|
hmmm..
No registers to set up
hmmmm.
so how does one select either A or B load cell input and the 'programmable gain' ? I did find a 9 page PDF..kinda missing a few 'minor' details...
edit: yeesh I finally really read the data sheet, page 4 ..variable SPI to program the device !!?? huh ?? still trying to figure that one out. Depending on # of clks the next data will be one of 3 available.
I can buy a loadcell and chip/module for $10..seems like a great deal...
Jay |
|
|
MikeW
Joined: 15 Sep 2003 Posts: 184 Location: Warrington UK
|
|
Posted: Sun Feb 04, 2018 1:30 am |
|
|
I guess I only used the A input, and the defaults were OK.
It certainly worked, and worked well.
I didnt use the HX711 in the end, due to its lack of availability of a distributor in the UK.
But it certainly worked.
It should certainly get @rosiley off the ground |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19513
|
|
Posted: Sun Feb 04, 2018 2:21 am |
|
|
Exactly like Mike. Just for the default reading.
You can select what you want using external pins.
From the data sheet:
Quote: |
There is no programming needed for the
internal registers. All controls to the HX711 are
through the pins.
|
The number of clock pulses you send controls the gain. You can set this with #USE SPI now (in the past you could not do this), or if you want just clock manually. You need to be using software SPI to give the option for this. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19513
|
|
Posted: Sun Feb 04, 2018 7:36 am |
|
|
Just to expand (looked up my notes), if you send 25 clocks, the next conversion is of channel A with a gain of 128. Send 26, and it gives you channel B with a gain of 32. Send 27 and it gives channel A with a gain of 64.
Understand it always controls the _next_ reading, and the data comes in on the first 24 clocks.
So potentially:
Code: |
#USE SPI (FORCE_SW, DI=YOUR_DATA_PIN, CLK=YOUR_CK_PIN, MODE=1, stream = HX)
//Then use
while (YOUR_DATA_IN==1)
; //wait for chip
val32=spi_xfer(HH,0,26); //select 26, 27 or 28 for what you want
//This will switch the chip to the specified mode.
//Default on wake up is CHA gain 128
//Then when you want to read:
while (YOUR_DATA_IN==1)
; //wait for chip
val32=spi_xfer(HX,0,24);
//val32 will now contain the 24bit reading from the chip
|
I remember this as being one of the most simple chips to drive I have ever met!.. |
|
|
|