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")
            print('Done Recording, plz save before close')

the button definition down lower is:

Class MyApp(App):
    def build(self):
        TDCRead = ToggleButton(text='Read TDC')

        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
        while i<32:
            byteback = self.__transfer(0x00)
            if j<4:
                f.write("Ref: %02X\r\n" % (byteback))
            elif j>=4 and j<6:
                f.write("Res: %02X\r\n" % (byteback))
                f.write("Res: %02X\r\n" % (byteback))
    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