Hi TJF
I have another problem which I can't identify.
It involves reading 1 input 24 times which "appears" to fail after correctly reading
about 16 to 18 bits, and then getting it wrong at least twice in the last 6 bits.
It involves 1 input (Data) and 1 output (Clk)
Basically the procedure is as follows.
For Xq = 23 to 0 Step -1
1. Wait for input to go Low
2. Send Clk output ON (which I manage to do in 23 micro sec's according to the CRO)
3. Within nano seconds of the Clock going Hi, the Data bit to read is valid.
4. Delay reading Data input with "For Xy=1 to 900:Next Xy"
If the Clk is Hi for more then 60 uSec the Data bit goes Hi and Stays Hi (Sleep mode)
The CRO output shows a vey reliable 20 uSec pulse, so untill the Clk is Lo the Data bit is valid.
5. Save the Data bit by "BitSet(BitValue,Xq)"
6. Clk output OFF.
7. Delay repeat to 1 above with "For Xy=1 to 250:Next Xy"
So clock Lo time is shorter then Hi time.
Next Xq
Now send the 25th Clock pulse to finish the transaction.
This pulse can be very short which is visible on the .pdf I send to you.
The example on the pdf shows:
000000101010101010100010 CRO Output
000000101010101010110011 PC Output
The first 16 to 18 bits are NEVER wrong.
I record all the readings and store them in both Integers and Bit string, so that I can
compare the bit string to the Integer.
Also there are sometimes a few "overshoot" spikes on the Clk, but it never shows
any spikes in the Data bit area (Blue Trace).
Typically it will read a 1 where there should be a 0.
Don't know if this complicates the debugging that you are doing, or shed light
either way I thought it may help.
Case 1 in the code below is the critical part.
Code: Select all
'----------------------------------------------------------
' Program to read HX711 A2D converter board.
' P8_11 is I/P of Data , P8_14 is Clock O/P
'----------------------------------------------------------
#INCLUDE ONCE "BBB/pruio.bi"
#INCLUDE ONCE "BBB/pruio_pins.bi"
Type Adcs
StepNbr As Integer
Init As Integer
Errer As Integer
End Type
Dim Shared Adc As Adcs
Type Accums
Counts(1 To 100) As Integer
AvgCount As Integer
Samples As Integer 'How many samples for each record (from Product.jvp)
Total As Double
HiValue As Integer
LoValue As Integer
End Type
Dim Shared As Accums Accum
Dim Shared As Double CalTime, GapTime,StartTime
Dim Shared as Integer StepInc, Xq,Xy,Xz
Dim Shared as Integer BitValue
Dim Shared BitStr As String * 24
Dim Shared io As PruIo
'=====================================================================
Sub GetA2D
With Adc
Select Case .StepNbr
Case -1 'Second call here if No Errer.
If .Init Then
.StepNbr = 1
EndIf
Case 0 'First call is here.
BitValue = 0
IF io.Gpio->config(P8_14 , PRUIO_GPIO_OUT0) THEN .Errer = 1 ''"P8_14 Config Error"
IF io.Gpio->config(P8_11 , PRUIO_GPIO_IN_0) THEN .Errer = 2 ''Print "P8_11 Config Error"
IF io.config() THEN
.Errer = 3
Exit Sub
EndIf
.Init = 1
.StepNbr = -1
Case 1 'Wait for next Data Rdy pulse.
Do
If StepInc < 1 Then
GapTime = (Timer - CalTime) * 1000 'mSec for gaps between reads.
StepInc = io.Gpio->Value(P8_11) 'If 1, then we have sync.
EndIf
If StepInc = 1 Then
If io.Gpio->Value(P8_11) = 0 Then 'When Zero, msb data is Rdy.
BitStr = ""
For Xq = 23 to 0 Step -1 '30 uSec later first Clck for 24 Bits
io.Gpio->SetValue(P8_14, 1) 'Set Clock ON.
For Xy = 1 to 900: Next Xy 'Wait 900 (23 uSec)
Xz = io.Gpio->Value(P8_11) 'then read state of bit
If Xz Then BitValue = BitSet(BitValue,Xq) 'Set Bit if Hi.
io.Gpio->SetValue(P8_14, 0) 'Got bit, so turn Clock OFF.
If Xz Then BitStr = BitStr + "1" Else BitStr = BitStr + "0"
For Xy = 1 to 250: Next Xy '100 = approx 2.5 uSec
Next Xq 'Do for 24 bits
io.Gpio->SetValue(P8_14, 1) 'Set 25th (end) Clock ON.
For Xy = 1 to 100:Next 'Short wait is ok for this one.
io.Gpio->SetValue(P8_14, 0) 'Set Clock OFF.
StepInc = 0 'Cancel Flag
.StepNbr = 2 'Go wait for Main
Exit Do
EndIf
EndIf
Loop
Case 2 'Crunch Data in Main loop & set next Step.
Case 3
If (((Timer - CalTime) * 1000) - GapTime) > 90 Then 'After 90 mSec,
BitValue = 0 :BitStr = "" 'Total time as per CRO 600 uSec
.StepNbr = 1 'start looking again.
EndIf
End Select
End With
End Sub
'=====================================================================
CalTime = Timer
Do
GetA2D
If Adc.StepNbr = 2 Then
Accum.Samples += 1
Accum.Counts(Accum.Samples) = BitValue
Adc.StepNbr = 3
Print "BitStr = ";BitStr
Print BitValue;" ";Bin(BitValue)
EndIf
If Adc.Errer > 0 Then Goto Err_End
If Inkey = "q" Then Exit Do
If Accum.Samples = 10 Then Exit Do
Loop
With Accum
.LoValue = &H7fffff
.HiValue = 0
For Xq = 1 to .Samples
Print .Counts(Xq)," ";Bin(.Counts(Xq))
If .Counts(Xq) > .HiValue Then .HiValue = .Counts(Xq)
If .Counts(Xq) < .LoValue Then .LoValue = .Counts(Xq)
.Total += .Counts(Xq)
Next
Print "Average = ";.Total / .Samples
Print "HiValue = ";.HiValue
Print "LoValue = ";.LoValue
Print "Variant = ";.HiValue - .LoValue
End With
End
Err_End:
Select Case Adc.Errer
Case 1
Print "Adc Clock Config Error"
Case 2
Print "Adc Bit Config Error"
Case 3
Print "io.Config Error"
End Select
End
EDIT:
Additional info.
The first time I switch the Clk output, I can't get it ON before 100uSec and then the Minimum ON time is 100 uSec,
which results in an invalid reading. I have ignored that until today and started looking and testing.
If I switch the Clk to zero first (which it already is) , and then switch it ON, it will switch within 40 uSec
and have the same pulse width as the rest (23 uSec).
REgards
Dinosaur