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.

TMS320F28334: Code is not running properly when in flash

Part Number: TMS320F28334
Other Parts Discussed in Thread: C2000WARE

Hi,

In my code I am running my routine at 50us using ADC interrupt triggered using PWM. My code is related to AC induction motor control.

At every 50us adc interrupt is generated and after taking adc value , I made ISR flag true. this flag I used in while loop to check and run my code.

In while loop I am calling some function which uses libraries of motor control and IQmath macros/functions.

In while loop I am using motor control and IQmath macros like ACIFE_MACRO, _IQsinPU etc. and doing some calculation.

when I run my code in RAM it runs properly and I toggle a gpio in while loop which toggle at every 50us. but when I run my code in flash the gpio doesn't toggle at 50us instead it toggle at 200us to 250us.

By commenting and uncommenting some part in routine I found that when I commented ACIFE_MACRO() the gpio is toggled at 100us.

after then I uncomment the ACIFE_MACRO and commented the _IQsinPU,_IQcosPU macros used in routine then the gpio is toggling at 150us.

Taking reference from HVACI_Senorless_2833x, I have used #pragma CODESECTION to copy the routine function which is in while loop.

When I use this and uncomment the ACIFE_MACRO and _IQsinPU, _IQcosPU the gpio is toggling at 150us.

So I commented the ACIFE_MACRO,_IQsinPU, _IQcosPU and use #pragma CODESECTION in code then gpio is toggling at 50us as expected.

this is what it looks like in code

void main()
{

.....

while(1)
{
if(adcisrflag)
{

//Toggle gpio and Do some routine
//Want to complete routine before next adcisr
}
}
}

_interrupt adc_isr() //adc isr is triggered at every 50us
{
adcisrflag = 1;
}

I think ACIFE_MACRO,_IQsinPU/_IQcosPU taking more time to run maybe.

can you please suggest any solution to this?

Thanks & Regards.

  • Hello Raj,

    Flash takes more time to execute than RAM because there are wait states. You can refer to the following tables in the device datasheet regarding the information about wait states.

    There will always be some amount of difference in access time when running from RAM versus Flash. Let me know if there are more questions about this, or if you are able to get the loop to run at the expected speed while running from Flash.

    Best regards,

    Omer Amir

  • Hi Amir,

    I understood that flash can take more time to run.Can you please suggest any solution for this? 

    ACIFE_MACRO,_IQsinPU/_IQcosPU is taking more time to run in flash. When I comment it loop is running as expected.

    Can you suggest any solution to run loop on time in flash for this?

    Thanks.

  • Hello Raj,

    This is a hardware limitation of Flash, I do not believe there is a way around it. Even if you are running the system at the max clock frequency, the Flash will need wait states to be able to read properly.

    Is there a reason you cannot have the program start in Flash and load certain functions to RAM? That way you can always start the application programmed from Flash while taking advantage of the RAM speeds for certain functions.

    Best regards,

    Omer Amir

  • Hi Amir,

    Can you please elaborate this? I don't understand what you meant to say by this.

    Is there a reason you cannot have the program start in Flash and load certain functions to RAM? That way you can always start the application programmed from Flash while taking advantage of the RAM speeds for certain functions.

    Thanks 

  • Hello Raj,

    Because the device has both RAM and Flash, and both can be programmed with executable code, there is a way to program your code onto Flash and then have certain functions in the code run from RAM. For an example of this for your device, you can refer to Example_2833xFlash in C2000Ware (C2000Ware_5_00_00_00\device_support\f2833x\examples\flash_f28335). Essentially there are preprocessor commands that can be used with a memcopy function to copy some program code from Flash to RAM to take advantage of the execution speed.

    Please take a look and let me know if you have any questions about this.

    Best regards,

    Omer Amir

  • Hello Amir,

    there is a way to program your code onto Flash and then have certain functions in the code run from RAM.

    I have doubt regarding it. Doesn't MCU when code is flashed  run that code into RAM taking from flash? Is this understanding right? Then why we have to run certain function from RAM. It will already run from RAM if flashed. What do you mean?

    I have referred the example you suggested. From that example I have used #pragma CODESECTION and memcpy in my code.

    I have not used InitFlash in my code. Do I need to add InitFlash in my code? If yes then why?

    What is exactly use of InitFlash? Can you please Tell me?

    Thanks.

  • Hello Raj,

    Doesn't MCU when code is flashed  run that code into RAM taking from flash? Is this understanding right? Then why we have to run certain function from RAM. It will already run from RAM if flashed. What do you mean?

    No, your understanding is not correct. When code is programmed to Flash as indicated in the command linker file using the sections such as .text, it runs from Flash. If it's programmed on RAM, it runs from RAM. The MCU does not operate like a computer where memory is pulled from a slower, larger memory unit to execute from RAM. Instead, the code is executed where it's stored. This is why it's noted in the datasheet regarding Flash timing/wait states, because program accesses are slower than if it was executing from RAM.

    I have not used InitFlash in my code. Do I need to add InitFlash in my code? If yes then why?

    What is exactly use of InitFlash? Can you please Tell me?

    If you looked in the example main code, there are comments above the function call:

    The function is used to set up wait states for Flash, to make sure accesses can happen properly without missing data (since Flash is slower to access than RAM, and the system clock is much faster than the Flash access).

    Best regards,

    Omer Amir