-
Notifications
You must be signed in to change notification settings - Fork 126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't read data when using external crystal #45
Comments
Hi, I have just tested the current library version with a HX711 modified with 20mhz crystal, and I have no issues. Also, as using an external crystal only changes the HX711 internal sampling rate, it should make no difference with respect to data transfer/library functions. So IMO there must be something else wrong. Did you try with any of the library example files? |
I have current library version and I connect the crystal directly across 13 and 14 pins according to datasheet. I tried with the multiple loadcell example. I also used 2 capacitors for connecting crystal but it wasn't required so it didn't matter. I'll try with a single loadcell example and report back in couple minutes. |
Yes, I did. I think it is originally connected to GND? but regardless those are disconnected and there is a 20mhz xtal across them now. To clarfiy it more, I then removed the xtal and soldered 2 jumper wires so now I can switch between internal and external on a breadboard, If I did wiring wrong, I can make a change easily. tried read_1x_loadcell example, connections are correct and I can retrieve data in my own sketch but not with this library. It is odd. attached sketch is working I had to modify the shift function to get it to work. |
Editing this part of conversion24bit function and all starts working, I have a little more noise then 80sps, not sure if this is expected or not, but it starts functioning. Config is set to 1 samples and no delays. |
It could very well be that your change: SCK 1 > SCK 0 > read DOUT is more correct then the library's SCK 1 > read DOUT > SCK 0. If so it's an easy fix if that's what needed. Strange thing is that I don't know of anyone else that have had the same issue. Can I ask what kind of MCU are you using, is it particulary slow or fast? BTW; yes you're right, pin 14 to GND enables the internal clock. |
I am using atmel32u4 on an Arduino Leonardo so nothing special, somehow this change makes it work and the other doesn't I am trying to figure out why because according to datasheet it should work either way. and more suprisingly none of the available hx711 libraries seem to work in my case. I also tried it with just an empty sketch and with a sketch which is really heavy (where I actually need to use the library) and it didn't work in both without this change. |
I have never tried the library with the 32u4. I don't fully understand what is happening other than that it seems to be timing related, but I will move the digitalWrite LOW anyway if it can improve library compability. Studying the data sheet, it is also done like this in the driver example on page 8. however, I need to do some testing first to check that the change works okay with other MCU's. |
Sadly, I don't have anything else around right now to test with exact hx711 and crystal setup, but I also believe it is a timing issue. |
I did some testing with Uno, Due and ESP8266, all good. Changes implemented in new release 1.2.2. |
I have investigated this further and this is a timing issue (I added microsecond delays by 1 each time and encountered exact same issue at some point not really far from 0 microseconds). There was one more issue with 20mhz crystal. I thought it is because of Arduino's digitalWrite() function speed and maybe I am losing some data (I am still not sure), This can be done just by writing into registers directly to set High and Low, I thought this issue is kind of okay to also include this information. |
Lots of strange things here... |
How does it work for you with previous version but doesn't work for me is strange. When I put a counter for a second and read load cell data and then read counter after a second, I get 145 with 20mhz, and 84 with internal oscillator. Serial plotter also moves faster and slower when I change oscillator. But it is functioning as expected when there is a force applied on it, so I can't point fingers at anything. I tried with 2 different Arduino, one is a normal clone, the other one is a little special and has better quality. They are both running 32u4 @ 16mhz. so it's not the 32u4, not the Arduino board, not hx711(same IC cheap or expensive board anyway, right?) doesn't work with old version of library, works with new version. One more question did you observe a drop in the read value switcihng between 80 and 144SPS as I have? About direct port manipulation, |
One more think, what capacitors are you using? Maybe that is why we are seeing different results. |
On the crystal? I think it's 22pF |
Thanks, I'll try but what do you think, I think I have tried enough different hardware. it is either crystal, capacitor or cheap hx711 (shouldn't be this one). Are you sure it is working on old version with 32u4 @ 16mhz? This is really strange. |
Yes, it's working fine with my 32u4 16mhz mini (china manufactured) also with old version library with the digitalWrite(sckPin, 0) in original position. Tested with 20mhz + internal osc, high rate and low rate. I don't see any noticable difference in noise changing from 20mhz to internal osc. I do see an offset in the output value comparing internal and external osc. but not much, its aprox. 2.5gr on a 1000gr load cell, so 0.25%. The Arduino 32u4 modules use a "real" crystal, not ceramic oscilator, so MCU frequency should be accurate within 50ppm and same as yours. |
I didn't know the last bit about 32u4. The noise offset looks to be right in line with my experience. so all looks inline with what I see here, so it must be my crystals I suppose, but lets assume they are a little over 20mhz, I still don't think it should cause such issue, maybe it does mess up with timings. They all say "20mhz" on them thought, maybe I should measure them for real, the measurementI do on arduino isn't that accurate but still lays right on 145sps (should be 144 with exact 20mhz but again not accurate)... well... About library and pulsing with port manipulation. I implemented a real simple method into the library, I don't plan to map ports to pin numbers arduino, it even changes between arduino type to arduino type, so when this method is used, correct register should be put into parameters for the correct pin, this is kinda low level and a special case anyway. At least this is the plan. Works with single loadcell, all good, no issues. |
I added some lines in the library .cpp file to roughly measure digital write time:
The result was 16us, sometimes 20us. That is for 2x digital write + some time to read the micros() value so I suppose each digital write is about 6-7us. Could you try the same? |
I just measured with oscilloscope using my 32u4 and library latest version: the SCK high time is 6.6us, well within the required range of 0.2-50us in the H711 data sheet. |
I don't have access to an oscilloscope right now but I did the changes and measured with my Arduino. My knowledge about how things work as of right now ends here, so I wonder if increasing xtal to 20mhz reduces the time windows? |
Closed due to no activity |
I am trying to use a 20mhz external oscillator with hx711 and according to its datasheet it is in spec.
When using 20mhz crystal, Reading data doesn't work and it only shows 0 and some high number when a force is applied.
I can read data with a quick test sketch I've made (didn't use the library) to check if all is working, so connections are right and oscillator is working.
The text was updated successfully, but these errors were encountered: