PIC24 -> USB -> MATLAB Plot

Discussion in 'Embedded Systems and Microcontrollers' started by blah2222, Jun 20, 2011.

  1. blah2222

    Thread Starter Distinguished Member

    May 3, 2010
    Hello, so I am currently working on the ADC conversion of a voltage signal for my PIC24 but I will eventually need to be able to send that data (in real-time) through a USB to my laptop and for a MATLAB plot to be generated.

    I have been reading up on how to do this and it says to save the data in DLLs or HEX files and then MATLAB translates and reads it, but I don't know where to start for that. My PIC24 has a USB setup and bootloader.

    Any ideas?
  2. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    Since you are interested in real time data you need to find a way that MATLAB can read something in real time. I can't help there as I never used MATLAB, but that is not a DLL or a hex file. Something should be there, like a serial port (RS-232) reader.

    Once you find a way MATLAB can read data then look inside the Microchip Application Library (MAL) for a demo program that does something similar. Example: if you can find a serial interface for MATLAB then you could adapt the Microchip "USB Host - CDC - Serial Demo" to your needs.

    That demo mimics a serial port thru the USB, and you could adapt it to send your A2D data back to the PC.

    It's mostly going to depend on what inputs MATLAB can accept.

    With an infinite budget and time you could define your own USB class and write a Windows driver for it. Otherwise it is far faster to reuse some existing class driver that is already inside Windows.
    blah2222 likes this.
  3. MrChips


    Oct 2, 2009
    Reading the USB port into MATLAB is straightforward. The USB appears as a serial port. Create a serial object using:

    s = serial('COM3');

    or on whatever COM port the USB appears.

    open the object via:


    and read the port using


    or whatever format you choose.

    This is all documented in the HELP menu.
    blah2222 likes this.