How to execute a subsystem only once in external mode (TI C2000 SPI peripheral configurat​ion/initia​lization)

16 views (last 30 days)
Blasé
Blasé on 3 Feb 2018
Commented: Blasé on 5 Feb 2018
Hey all,
I need some help getting my project up and running. I have a LAUNCHXL-F8377S and I'm using a LS7366R quadrature counter (<http://www.lsicsi.com/pdfs/Data_Sheets/LS7366R.pdf>) that reads the A/B pulses from an encoder and stores that data into a counter to be read via SPI. The counter needs to be configured on start up by writing data to a sequence of registers. After it is configured, I can read the counter over and over by writing (then reading) to the same register. This would be fairly simple in CCS, but I'm trying to use the Embedded Coder Support Package for Texas Instruments C2000 Processors in Simulink.
Simulink doesn't seem to have a good way to run certain blocks as part of an initialization sequence and ignore them for the rest of the model's execution. On top of that, I need to do this in External Mode, which may be adding additional difficulties. There's an example of essentially the same process being done using the Arduino Support Package for Simulink, and I've linked it below:
https://www.mathworks.com/help/supportpkg/arduino/examples/communicating-with-an-spi-based-eeprom-using-arduino-hardware.html
Basically, it uses the delay block to trigger the One_time_intialization subsystem on the first time-step and runs the execution loop thereafter. Because it works for Arduino, I suspect there's some other configuration I need to do to make this work with the LAUNCHXL-F8377S. I've replicated this using the C2000 Support Package by changing the contents of the One_time_configuration block with the following:
Here, I connected the MOSI to the MISO pin on the board so I'm reading what I'm transmitting. Then I send the integer I transmitted/read into a PWM module to set a duty cycle for viewing on an oscilloscope. When I run the model in external mode, the SPI Transmit block within the One_time_initialization subsystem is still able to transmit despite the fact that the loop should have been exited and never entered again. I know this because when I update the value being fed into the SPI Transmit block, the duty cycle on the ePWM changes.
I know there might be a better way of doing this, so I'm open to suggestions (Stateflow?). If I can make sure the One_time_initialization subsystem is only executed once, then I can use a for loop to send the configuration commands in a sequence before continuously reading the counter in the execution loop like this:
This is perhaps less of a question about SPI and more a question about how to execute a set of commands only once when coding the launchpad using the C2000 Support Package in Simulink. Any help would be greatly appreciated and if you could point me to any helpful links that help with timing events in Simulink, that'd be great.
Thanks,
B

Accepted Answer

Venkatesh Chilapur
Venkatesh Chilapur on 4 Feb 2018
Please can you attach your model for further analysis. We also have a model on the same lines for C2000 for i2c protocol. 'c28x_i2c_sensor'
  1 Comment
Blasé
Blasé on 5 Feb 2018
This helped me figure out my issue. The key difference was the rate transition that went from the unit delay to the execution loop. I'm not sure why this helped, but I'm glad it did.

Sign in to comment.

More Answers (1)

Madhu Govindarajan
Madhu Govindarajan on 5 Feb 2018
If I am understanding your question correctly, all you are looking for is a way to run initialization routine and then start execute something else for the rest of the time.
The simplest way would be to use enabled subsystems just like you are doing, but with a small modification. The initialization subsystem would get enabled only for as long as the delay block is outputting zero. In my case a unit delay was sufficient.
For more details, download this submission and check out PitchControlArduino.slx > IMU Data read has both the blocks shown in this image.
https://www.mathworks.com/matlabcentral/fileexchange/63397-arduino-and-beyond-webinar-files

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!