Electronic – Reading from multiple sensors and synchronizing data

pictimeruart

I am working on a project which requires reading from four sensors simultaneously with time stamps down to millisecond.

Right now the best I can come up with is to use four PICs to read from each sensor and output through four RS232 to a laptop. So those sensors don't interfere with each other. For time stamps, I use a mechanical switch to trigger a external pin voltage change interrupt to start timers in all PICs at the same time. Timers increment every one millisecond and I just simply append the value from timers at the end of every measurement and output them through serial ports.

It works but I just want to know if there is a better solution since this project is kind of time critical (1000 measurements per second required). And also internal timer for each PIC varies which defeats the purpose of synchronizing timers.

I also thought about just reading from one additional chip's timer using SPI so all time stamps come from one source. However, I don't know when those PICs will read the time from that source chip. There could be four PICs reading from it at the same time which will mess up time stamps.

Sensor 1: Quadrature encoder (channel A B and Index)

Sensor 2: Laser (sending measurement back through Rs232 interface)

Sensor 3: accelerometer (analogue)

Sensor 4: inclinometer (RS232 interface)

I am using four DSPIC30f4011 chips. They have QIEs enough UARTs and also support four channel simultaneous ADC.

For Quadrature encoder, I use an on chip QIE to read from it and send measurement to a laptop through UART.

For Lazer and inclinometer, I read from them through UART1 and send measurements to a laptop through UART2.(one chip for each of them)

For accelerometer, x y and z information are being collected using four channel simultaneous mode. Measurements are sent to a laptop through UART.

Best Answer

Okay, we have some info on the sensors.

This should be doable with one of the newer dsPIC33Fs. As @gbarry correctly notes, they have variants that can do 4 channel simultaneous sampling (i.e. they have 4 sample and holds)

dsPIC sim samp

I am currently using one of these for some experimentation, the dsPIC33FJ64GP802. It's an impressive little chip, much better than the older dsPIC30F4011s. It runs at up to 40 MIPs, and has an 8-channel DMA which you can use for the ADC and other peripherals, so getting your timing within spec should be not so hard. The DMA makes life much easier, you can use it plus interrupts to save your main loop as much as time as possible.
You also have 2 UARTs, and 4 capture/compares (for the quad encoder) plus 5 timers.

You are missing 1 UART, so you will neither need to bit bang or add an external UART IC if you can't find a variant with more than 2 UARTs.

There are a few versions to choose from, the one I linked to is one of the smaller ones memory wise (I was mainly interested in the ADC and audio DAC plus DMA for audio ideas prototyping), so have a browse through all the options.