I have started a project using Max127 and VB6
There is a problem in this Code area.
Dim N As Long
Dim Report(8) As Byte
' MAXIM127 control byte
' START, I = Channel index, 0-5 V = RNG 1 and BIP 1, normal operation
Report(3) = &H80 Or (I * 16)
Ret = IowKitWrite(IOWarrior, IOW_PIPE_SPECIAL_MODE, Report(0), 8)
' read answer containing voltage value
Ret = IowKitRead(IOWarrior, IOW_PIPE_SPECIAL_MODE, Report(0), 8)
' extract bytes of value
N = (Report(2) * 256) Or Report(3)
' value is upper 12 bits of 16 bits
N = N / 16
If Report(2) has a value > 127 then the program crashes due to overflow because (Report(2) * 256) > 32768. On the 0-5 v Scale this represents a value of 2.50 v. i.e. 50% of full scale. From 0 to 2.50 v system works OK.
Any idea what is causing this?
MartinP
IOWarrior24 MAX127.vbp Problem with VB6 code crash
Moderator: Guido Körber
-
- Posts: 543
- Joined: Mon Dec 01, 2003 6:09 pm
MAXIM127.vbp
Hi Robert
Thanks for your prompt reply.
Unfortunately, although the program doesn't crash now, it is OK for 0 to 2.50 volts (ie 50% input) but displays decreasing negative values for input voltages in the range 2.50 to 5.00 volts. Could be something to do with the shift right / shift left function carried out by Report(3)???
Any ideas?
Thanks
Martin
Thanks for your prompt reply.
Unfortunately, although the program doesn't crash now, it is OK for 0 to 2.50 volts (ie 50% input) but displays decreasing negative values for input voltages in the range 2.50 to 5.00 volts. Could be something to do with the shift right / shift left function carried out by Report(3)???
Any ideas?
Thanks
Martin
-
- Posts: 543
- Joined: Mon Dec 01, 2003 6:09 pm
MAXIM127.vbp Code
Hi Robert
I have fixed my problem by reassigning N (Long) to a new variable, M (Integer). I’m not sure of the reason but the following code appears to work properly now !!
N = Report(2) ' The “And &HFF” does not work
N = N * 256
N = N Or Report(3)
N = N / 16 ' value is upper 12 bits of 16 bits
' value is 12 bit signed!
' We need to add the upper twos complement sign bits for the Integer.
' This is a sign extension from 12 bit to 32 bit.
If (N And &H800) <> 0 Then
N = N Or &HFFFFF000
End If
Dim M As Integer
M = N ‘assign to Integer (M)
‘value now is a signed integer with 2047 = 10 V and -2047 = -10 V
Values(I).Caption = Format(M * 10# / 4096#, "0.000") ‘for +/- 10 v scale
Thanks a lot for your assistance. Hopefully, this can help others
Regards
Martin
I have fixed my problem by reassigning N (Long) to a new variable, M (Integer). I’m not sure of the reason but the following code appears to work properly now !!
N = Report(2) ' The “And &HFF” does not work
N = N * 256
N = N Or Report(3)
N = N / 16 ' value is upper 12 bits of 16 bits
' value is 12 bit signed!
' We need to add the upper twos complement sign bits for the Integer.
' This is a sign extension from 12 bit to 32 bit.
If (N And &H800) <> 0 Then
N = N Or &HFFFFF000
End If
Dim M As Integer
M = N ‘assign to Integer (M)
‘value now is a signed integer with 2047 = 10 V and -2047 = -10 V
Values(I).Caption = Format(M * 10# / 4096#, "0.000") ‘for +/- 10 v scale
Thanks a lot for your assistance. Hopefully, this can help others
Regards
Martin