This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Linux/AM3358: Building an interrupt timer

Part Number: AM3358
Other Parts Discussed in Thread: ADS8860

Tool/software: Linux

Hi,

i'm very new in embedded systems, and i'm working with beaglebone black rec C, so i'm reading data from an ADC (ads8860) from the SPI0, and send the data to a software via UARTx everything is ok, but now i need to implement a timer interrupt to read the values from the adc, every 2us (500 kHz).

Currently, i'm working from Putty, building in Python, but i can do in C# too.

The line of code in def read_adc-> time.sleep(0.000002) doesnt do what i want, thats why i need a timer interrupt.

Code:

#libs
import time
import spidev
import serial
import Adafruit_BBIO.UART as UART

#config UART
UART.setup("UART1")
disp = serial.Serial(port ="/dev/ttyO1", baudrate = 115200 )

#configs SPI
spi = spidev.SpiDev()
spi.open(1,0)
spi.max_speed_hz = 24000000
spi.mode = 1
spi.lsbfirst = False
spi.threewire = False
spi.cshigh = True


#configs rs232



global msb,lsb
global NA

def read_adc():
        a = spi.readbytes(2)
        msb = a[0]
        lsb = a[1]
        time.sleep(0.000002)
        #b = 256 * msb + lsb
        #c = float(int(b)*5) / 65535
        #print c,'V'
def send_data():
        disp.write('D')
        disp.write('L')
        count_na = 0
        while True:
                read_adc()
                disp.write(msb)
                disp.write(lsb)
                count_na = count_na + 1
                if count_na == NA:
                        break
def protocol():
        while True:
                buffer = disp.read(1)
                count = 0
                if count == 0:
                        if str(buffer) == 'I' | str(buffer) == 'R':
                                count == 1
                                print 'Recebeu:', buffer
                if count == 1:
                        if str(buffer) == 'N':
                                print 'Recebeu:',buffer
                                count = count + 1
                        if str(buffer) == 'T':
                                print 'Recebeu:',buffer
                                count = 0
                if count == 2:
                        FA = buffer
                        count = count + 1
                        print 'FA = ',FA
                if count == 3:
                        NA = buffer
                        print 'NA = ',NA
                        send_data()
                        count = 0

while True:
        protocol()

device tree to SPI0:

elinux.org/BeagleBone_Black_Enable_SPIDEV

Any help will be aprecciate.

Best Regards,

David  

  • Hi David,

    I understand that you're workin in user space, right?

    In that case you could integrate the usleep function in your application. Otherwise you'll need to create/use hrtimers (create/modify linux kernel driver) which generate interrupts once every 2 us. You can find a guide on hr timers in Documentation/timers/hrtimers.txt & Documentation/timers/highres.txt, also see the following community discussion:
    stackoverflow.com/.../how-would-one-go-about-generating-artificial-interrupts-in-the-linux-kernel

    Best Regards,
    Yordan
  • Hi Yordan,

    Thanks for the advice, i just have acess to an osciloscope next week to test the usleep function.

    And i have no experience working with linux kernel drivers, i'm still a student, still have a lack of experience in this area. But i still done a lot of researches, and i find out about working with the CCS and StarterWare, to use the DMtimerCounter, but i'm having problmes connecting the software to the board, so i put that apart for now.

    Another thing, is the interrupts in the dts files like code lines like:

    interrupt-parent = <&intc>;
    interrupts = < 1 0 >;
     

    so i have my dts file to SPI0,   and i read about this interrupts, but didnt understand much, and i wnat to ask if is possible do the delay i want through these interrupts?

    Thanks again for the previous previous advices.

    Best Regards,

    David