Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 3 of 3

Thread: How to Read Multiple Sensors on the same teensy?

  1. #1
    Junior Member
    Join Date
    May 2022
    Posts
    2

    How to Read Multiple Sensors on the same teensy?

    I am trying to read multiply sensors on my teensy 4.1 using Teensyduino. Each sensor is on its own SPI port. The problem I am running into is that each sensor has its own rate that it runs at. For example I have one sensor that runs at a period of 5 ms and takes 250 us to read the data. I have another at 2000 hz and takes 150 us to read the data. And finally a third at 4000 hz that takes 20 us to read the data. I'd like to have an interrupt for each sensor and then run the data reading on some sort of prioritized thread but arduino/teensyduino doesn't seem to have that capability. I have looked at tons of third party schedulers, "threading" libraries but none of them allow me to interrupt the slower 5ms sensor that takes 250 us to read. It would make sense to be able to let that 5ms sensor begin reading the data and interrupt it to get the 4000 hz data and then continue reading the data. Has anyone done this using Teensyduino? Any recommendations?



    Interrupt 1 ------+--------+---------+-------
    ReadSensor ------- +++-----+++------+++-
    Interrupt 2 --+--+--+--+--+--+--+--+--+--
    ReadSensor---+--+--+--+--+--+--+--+--+-

  2. #2
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    16,019
    Look at TeensyThread perhaps?

    With the devices being on separate SPI buses it isn't guaranteed to fail - but it may not work reliably having the processor pulled away and interrupted during an active read.

    Setting up three threads each getting their own sensor data and doing thread.yield when done perhaps should reserve as much time for any other threads to do 'work' on the data as it accumuolates.

    Similar could be done MANUALLY with IntervalTimer interrupts where each gets an appropriate level of priority where one would interrupt the lower ones.

  3. #3
    Junior Member
    Join Date
    May 2022
    Posts
    2
    @defragster Thanks. The teensythreads looks like its doing the job.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •