I am having an issue getting the exact same value for example if I am entering ushort as &HFA91 which is equal to 2705 Dec but instead of 2705 I am able to read 2507 similarly if I am entering 3000mV which is 3V the output reduces to 2.87V automatically. I am not able to read exact values. Why is that so? Is it because of my timer or am I not initializing the variables properly or what
Initializing 16 bit data
Public byte_ vall As UShort &HFA0
Writing commands here
Private Sub Writecommand(ByVal add As Byte, ByVal val As Byte) Dim crc(1) As Byte Dim writecommandCMD(7) As Byte writecommandCMD(0) = deviceID writecommandCMD(1) = 6
writecommandCMD(2) = 0
writecommandCMD(3) = add writecommandCMD(4) = val writecommandCMD(5) = 0
crc Me.CRC(writecommandCMD) ' Call CRC Calculate.
writecommandCMD(6) = crc(0) writecommandCMD(7) = crc (1)
Thread.Sleep(100)
End If End If
' Echo received
CommandSent = 1
Writing commands in 500mS subroutine
Sub Timer500ms_Tick(sender As Object, e As EventArgs) Handles Timer590ms.Tick timCount + 1 Select Case cmd 'And cmdl Case ReadDataRegisters(deviceI0)
cmd 1 Case 1 ReadConfigRegisters(deviceID)
cmd = 0
Case 2 Writecommand(3, byte_vall >> 8 And &HFFF)
cmd 2
Case 3 Writecommand(3, byte_vall And &HFFF)
Case Writecommand(6)
Case Else
End Select
I have a form in which I have one button and when it’s clicked the command write value (cmd=2) updates the value
`
Private Sub cal_out_btn(sender As Object, e As EventArgs) Handles Calibrate.Click
Form1.OUTPUT_VOLTAGE Forml.byte_vall Forml.cmd = 2
End Sub`
I have tried entering &H505 and I am able to read correct output which is 1285 Dec but when I enter value such as &HA91 I am reading 2507 instead of 2705 why is that so do I need to convert it to strings or what ??