Jump to content
  • 0

pmodisns20 Problem


sergiodorazio

Question

Hi,

I am working with Digilent Discovery 2 and PMODISNS20 board for current measure. The system work but sometime (every about 20 time) the VB code read a bad value of current. I send you my VB source code. Can you help me to found the problem or you send me an example code ?

        dwf.FDwfDeviceOpen(-1, hdwf)

        Threading.Thread.Sleep(20)

        dwf.FDwfAnalogIOChannelNodeSet(hdwf, 0, 0, 1.0)
        dwf.FDwfAnalogIOChannelNodeSet(hdwf, 0, 1, 3.3)
        dwf.FDwfAnalogIOEnableSet(hdwf, 1)

        Threading.Thread.Sleep(170)

        dwf.FDwfDigitalSpiSelect(hdwf, 0, 1) ' CS DIO-0 high

        dwf.FDwfDigitalSpiFrequencySet(hdwf, 20000.0)

        dwf.FDwfDigitalSpiClockSet(hdwf, 2)

        'dwf.FDwfDigitalSpiDataSet(hdwf, 0, 1) ' 0 DQ0_MOSI_SISO = DIO-1
        dwf.FDwfDigitalSpiDataSet(hdwf, 0, 1)

        dwf.FDwfDigitalSpiModeSet(hdwf, 1)

        dwf.FDwfDigitalSpiOrderSet(hdwf, 1) ' 1 MSB first

        Dim bbRx(2) As Byte
        Dim bbRx1 As UInteger

        Dim corrente As Double = 0
        Dim average As Double = 0
        Dim somma As Double = 0

        ' spurius reads
        For c = 0 To 5
            dwf.FDwfDigitalSpiSelect(hdwf, 0, 0) ' CS DIO-0 low
            dwf.FDwfDigitalSpiRead(hdwf, 0, 8, bbRx, 2)
            dwf.FDwfDigitalSpiSelect(hdwf, 0, 1) ' CS DIO-0 high
            Threading.Thread.Sleep(3)
        Next

        Threading.Thread.Sleep(30)

        For c = 0 To 20

            dwf.FDwfDigitalSpiSelect(hdwf, 0, 0) ' CS DIO-0 low
            dwf.FDwfDigitalSpiRead(hdwf, 0, 8, bbRx, 2)
            dwf.FDwfDigitalSpiSelect(hdwf, 0, 1) ' CS DIO-0 high

            bbRx1 = (bbRx(0) * 256 + bbRx(1)) / 2
            corrente = (11.117 * (bbRx1 - 2048))

            somma = somma + corrente

        Next

        average = somma / 20

        dwf.FDwfDeviceCloseAll()

        WriteRichTextBox1(vbCrLf)
        WriteRichTextBox1("Current detector average ")
        WriteRichTextBox1(average)
        WriteRichTextBox1(" mAmp ")
        WriteRichTextBox1(vbCrLf)

 

 

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...