To store ADCC samples in a file, one way of doing this is to run a loop in the ADCC ISR that saves a block of data to memory e.g. the following code stores NUM_SAMPLES (the number of channels sampled each time the ADC ISR runs) NUM_BLOCKS times, and then loops around and starts at the start of the block
block_index = blocks*NUM_SAMPLES;
for (i=0;i<NUM_SAMPLES;i++)
{
i_block[block_index+i]=SampleBuffer[i]; //Store in memory block
}
blocks++;
if (blocks==(NUM_BLOCKS-1)) //If we have filled all the memory blocks, start again at the beginning
{
blocks=0;
}
An IAR macro (see the IAR Embedded Workbench documentation for more details on how to set these up and run them) can be used to extract the data from memory into a text file, which can in turn be imported into MATLAB, from where it can be used as a vector of data into Simulink (look at MATLAB help documentation for text import, converting string to number etc.)
Sample macro code is below
__var _fileHandle;
__var startaddr, endaddr;
SaveADCData()
{
startaddr=0x2003073c; //This address needs to be manually entered
endaddr=0x20031614; //This address needs to be manually entered
__var memdata;
__var memloc;
OpenSaveFile();
for (memloc=startaddr;memloc<endaddr;memloc=memloc+2)
{
memdata= __readMemory16(memloc, "Memory");
__writeFile(_fileHandle,memdata);
}
CloseSaveFile();
}
OpenSaveFile()
{
_fileHandle = __openFile("$PROJ_DIR$\MemData.txt", "w");
if( !_fileHandle )
{
__message "Could not open file.\n";
}
else
{
__message "File open.\n";
}
}
CloseSaveFile()
{
__closeFile( _fileHandle );
__message "File closed.\n";
}