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.

LAUNCHXL-F28379D: Read 5 ADC slaves using SPI interface via LAUNCHXL-F28379D Simulink

Part Number: LAUNCHXL-F28379D


Hi guys,
I need to read 5 ADC chips (5 slaves) (MCP3208) using the SPI interface with a sampling time of 0.00013s. Each ADC has 8 channels (I need to read 36 of 40 channels). I need to do this using Matlab Simulink R2017b.
I am able to read 8 channels (1 ADC) within 0.00013s using the attached model. Also, I am able to read 16 channels but the sampling time is reduced to half of the required time (0.00013s) automatically (I have set each "Receive Block" with 0.00013 So SPI took 0.00026s to read 16 channels). Please see the attached. Please note that even if the system is working with 16 channels but I am still getting this error "Not enough memory on the target to process the packet: EXT_SETPARAM" (I have changed the "Duration" of the "External Mode" setting from 1000 to 5 but I am still getting the same message).
So my questions are
2) How can I read 5 ADCs (5 GPIO are used to read 36 channels) within 0.00013s?
Please note that I am getting the following errors when
1) I set the "sampling time" of the "Receive Block" as 0.000026s (=0.00013/5).
The error is:
"Invalid setting for fixed-step size (1.0E-5) in model 'SPI_C'. All sample times in your model must be an integer multiple of the fixed-step size.
Component: Simulink | Category: Model error
The sample time period (2.6E-5) of 'SPI_C/Subsystem/SPI Receive' is not an integer multiple of the fixed step size (1.0E-5) specified for model"
2) when I choose "enable blocking mode"
The error is:
An error occurred while executing External Mode MEX-file 'ext_comm':
Failed to connect to the target. A time-out occurred while waiting for the connection response from the target. Possible reasons for the time-out:
a) The target is not switched on.
b) The target is not connected to your host machine.
c) The application for the model is not running on the target. You might have clicked the Stop button. If the Run button is not dimmed, click it. Otherwise, click the Build button, which downloads and runs your application on the target.
Thank you in advance
  • Ashraf,

    I'm going to need a few days to consult with the MW team on the above, especially on the correct way to partition the SPI to read the external ADCs.

    I can comment on the error related to the sample rate, I'm assuming that MW allows you to enter a free form number for this.  However, the SPIs will be clocked off the main CPU clock(200MHz) and have an associated pre-scalers, etc so that your sampling rate will ultimately need to be a integer of this.  I need to dig out the formula to derive this easliy.

    I also need to better understand from the MW team what blocking mode does exactly.

    Best,

    Matthew

  • Hi MatthewPate,
    Thank you for replying, I am waiting for your answer
    I just would like to add some more notes

    1) I am able to read 5 external ADCs using my model. After changing a little on the model, the "NOT ENOUGH MEMORY..." error is gone (please see Fig.1). In Fig.1, 4 external ADCs are used.

    2) Actually, I need to run the whole system (3 ADC pins to read 3 ADC values, Matlab function to write my algorithm, SPI_C (only 1 GPIO is used) to transmit some values, SPI_A (5 GPIO are used) to read 5 external ADCs ) with 0.00013s. Note that, SPI_C takes its input values from the "Matlab function" block, So, I set its sample time within the "Matlab Function" block. SPI_A takes specific values to determine which ADC channel that we need to read each time, so, I set its sample time within the "constant" block and in "SPI_A Receive block". By using SPI_A and SPI_B (6 GPIO), the duty cycle (or the sample time) (measured using an oscilloscope) is reduced so much (around 800us). So, I was trying to improve the duty cycle value by playing with the "Desired baud rate" of SPI. I noted that the duty cycle becomes better (close to my desired time 0.00013) when I am reducing the "Desired baud rate" value but when reduced it a lot, the error percentage of the data read from the external ADCs becomes very high, Please see Fig.2 and Fig.3, the duty cycle is reduced from 420us to 317us but it is still not what I need (please note that I increased the sample time inside all the Simulink Blocks to be 0.00001s which let the Simulink model working slowly).
    My main concern is to make the duty cycle in Fig.2 and Fig.3 as 0.00013 (130us).

    3) In the "Clocking" option, I thought the duty cycle will be better when I reduced the value of "Oscillator clock frequency (OSCCLK) from 10 to 8 but I got the following error
    "Error occurred while executing External Mode MEX-file 'ext_comm':
    Failed to connect to the target. A time-out occurred while waiting for the connection response from the target. Possible reasons for the time-out:
    a) The target is not switched on.
    b) The target is not connected to your host machine.
    c) The application for the model is not running on the target. You might have clicked the Stop button. If the Run button is not dimmed, click it. Otherwise, click the Build button, which downloads and runs your application on the target."

    Thank you very much

  • Ashraf,

    Looking at the tasks you have planned to perform, it may be difficult to complete within a period of 130us.
    I suggest you to compute the time taken to read 8 channels (1 ADC ) and see how much time it is taking.
    Refer to the below link to measure the code execution time using custom code block:
    https://e2e.ti.com/support/microcontrollers/c2000/f/171/t/943879

    The time computed above helps to determine if it is feasible to read 5 ADC within 130us with the current design.

    If you feel any support is required, it would be best for you to get in touch with our support channel. When we have a support ticket, our internal process enables us to involve right people on this issue and we will immediately get in touch with you to understand the case in more detail way.

    Please connect to us at:
    https://www.mathworks.com/support.html

    Regards,
    Ram Alla.