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.

TMS320F28335: Calling standard library printf function disrupts PWM outputs

Part Number: TMS320F28335

Hello there

I am generating 3-phase PWM outputs using the PWM peripherals. A timeout event from the PWM timer generates an interrupt and in the corresponding ISR the duty cycle is varied.

Now I want to send and receive information to and from the microcontroller using the stdio.h library functions. So after all relevant initialisation, I have a printf statement in an empty while(1) loop that the program is confined to while waiting for the next timer interrupt. This is the only printf statement I have put in. So, according to my understanding this shouldn't have any effect on the PWM outputs as it should be interrupted and temporarily suspended while the ISR runs, then allowed to resume once the ISR has finished.

However, when i view them on my oscilloscope, the PWM outputs are disrupted and when I close the debug session in CCS, thereby removing the connection between the microcontroller and the CCS console which it prints (successfully) to, the PWM outputs go back to behaving as expected. 

So why is this happening? Are there higher priority interrupt routines at work within the printf function that cannot be interrupted by my PWM timers? How can I fix this so that it will print strings to the console without disrupting the PWM?

Thanks for taking the time to read.

Regards

Josh

  • Hello Josh,

    The printf function inserts a software break-point to format and export the specified string. That break-point halts the DSP while the string is exported over the emulation link. Typically that takes a few thousand cycles.

    What is happening is your (ISR) code which modulates PWM duty cycle does not get called because the break-point halts the device while the de-bugger reads out the CIO buffer. You should not be seeing the PWM stop because that runs in hardware, but you may lose the duty cycle update temporarily while the printf takes place.

    There are a couple of web resources here which may help you understand the background:
    http://processors.wiki.ti.com/index.php/Tips_for_using_printf
    http://processors.wiki.ti.com/index.php/Printf_support_in_compiler

    This is always going to happen when you use one of the stdio print functions. I can only think of two ways to avoid the issue:
    - You can transmit the message over some other communications port, for example over SCI with an RS232 link to your PC.
    - Alternatively, if you are prepared to port your project to use BIOS, there is a LOG_printf function available which does not have this issue.

    Regards,

    Richard

  • Josh,

    As Richard said, the printf routine goes through the debugger pod, slows down the operation, and can't be used without the debugger plugged in. If your product has a UART/SCI port available, here's what we do. We use sprintf to generate the formatted buffer, then use interrupt driven code to send it out the UART port.

    Lloyd
  • Thank you both for your replies. This is a big help. Much appreciated.