Linked Questions

Popular Questions

I am using a Raspberry Pi 3b to collect data over SPI from a time-to-digital converter (TDC-GPX2). The TDC essentially marks when in sees an event (rising edge of an electrical pulse let's say) and sends its timing information to my Pi. My goal for this would be to collect data without pause (as missed pulses increase error chance in my data), as fast as possible, until a toggle is flipped off.

Note: We are developing LVDS comm drivers on our FPGA for faster data acquisition from the TDC, but this would help with quick tests and other projects. We're using spidev for the SPI Also: I realize requesting all 4 stops' information isn't efficient but I can adjust that later

I'm using Kivy as the gui solution for this software, I'll show the important snippets of code below. I'm using a main code with the gui and a library for the TDC with the loop inside it. I've never posted here before so I'm not sure what to include in the code, if more is needed I'll post it! I did try the "thread" library but it seemed to be really unresponsive and slowed down the gui dramatically.

def press_callback(obj):
    global tdcinit, f
    print("Button pressed,",obj.text)

    if obj.text == 'Read TDC':
        if obj.state=="down":
            f.write("New Trial \r\n")
            TDC.ReadTDC(f,obj.state)
        else:
            TDC.ReadTDC(f,obj.state)
            TDC.Reset()
            print('Done Recording, plz save before close')

the button definition down lower is:

Class MyApp(App):
    def build(self):
        layout=GridLayout(cols=5)
        Window.clearcolor(0.2,0.2,0.2,1)
        TDCRead = ToggleButton(text='Read TDC')
        TDCRead.bind(on_press=press_callback)
        layout.add_widget(TDCRead)

        return layout

The function in my TDC library being called is:

def ReadTDC(self,f,state):
    while state=='down':
        GPIO.output(29,0) #this is just for SPI
        i=8
        j=1
        self.__transfer(0x68)
        while i<32:
            byteback = self.__transfer(0x00)
            if j<4:
                f.write("Ref: %02X\r\n" % (byteback))
                j=j+1
            elif j>=4 and j<6:
                f.write("Res: %02X\r\n" % (byteback))
            else:
                f.write("Res: %02X\r\n" % (byteback))
                j=1
            i=i+1
        GPIO.output(29,1)
    return f

The __transfer function is really just using xfer2 and printing the results for debugging.

I had hoped this would work as a "Press ToggleButton named Read TDC and the loop runs until I press the toggle again," but it just focused the loop until I ctrl+C'd my way out.

Related Questions