1

I have a PIC24 based system equipped with a 24 bit, 8 channels ADC (google MCP3914 Evaluation Board for more details...). I have got the board to sample all of the 8 channels, store the data in a 512x8 buffer and transmit the data to PC using a USB module when the buffer is full (it's is done by different interrupts).

The only problem is that when the MCU is transmitting data (UART transmission interrupt has higher priority than the ADC reading interrupt) the ADC is not sampling data hence there will be data loss (sample rate is around 500 samples/sec). Is there any way to prevent this data loss? maybe some multitasking?

Muhammad
  • 89
  • 1
  • 5

3 Answers3

2

Simply transmit the information to the UART register without using interrupts but by polling the bit TXIF

while (PIR1.TXIF == 0);
TXREG = "the data you want to send";

The same applies to the ADC conversion : if you were using interruptions to start / stop a conversion, simply poll the required bits (ADON) and thats it.

The TX bits and AD bits may vary depending on your PIC.

That prevents the MCU to enter an interrupt service routine and loose 3-4 samples.

Jean-francois
  • 316
  • 1
  • 9
  • 1
    Worked for me, thanks! I kept the sampling using interrupts but the transmission is done now by polling without interrupts... – Muhammad Jun 16 '14 at 12:27
1

In PIC24 an interrupt can be assigned one of the 8 priorities. Take a look at the corresponding section in the "Family Reference Manual" -> http://ww1.microchip.com/downloads/en/DeviceDoc/70000600d.pdf

Oleg Mazurov
  • 497
  • 5
  • 10
1

Alternatively you can use DMA channels which are very handy. You can configure your ADC to use the DMA, and thus sampling and feeding the buffer won't use any CPU Time, same goes for UART I beleive.

http://ww1.microchip.com/downloads/en/DeviceDoc/39742A.pdf http://esca.atomki.hu/PIC24/code_examples/docs/manuallyCreated/Appendix_H_ADC_with_DMA.pdf

Damien
  • 1,492
  • 10
  • 32