Skip to main content
sanju
Associate III
May 3, 2018
Question

DMA With TIM3

  • May 3, 2018
  • 7 replies
  • 1359 views
Posted on May 03, 2018 at 13:24

Waclawek.Jan

‌

ELMHIRI.Syrine

‌

Turvey.Clive.002

‌

Hi all,

I have to generate a PWM signal of 15%,40KHz  with a short pulse in response with a input.

the task is, at initial the input state will be low. when input will become high then for 450us to 500us the output of should be high and then output switch to PWM signal of 15%,40Khz. and continue till input is high. As input becomes low the output should become low.

I have done it and it's running ok.

I have configure the input signal in interrupt mode for rising and falling edge both. and configured TIM3 Registers (PSC, ARR, CCR) for pwm 15%@ 40KHz.

The timer will continue run but I have put TIM3_CH1 at forced low mode at initial so output will low. when input will become high it will generate a interrupt and in ISR it will put TIM3_CH1 to Forced high mode  so output will high. and it will return from ISR to main function and will check for CC1IF bit state and count up to 20 (i.e. it will check for 20 pulses of 40Khz = 20*25us = 500 us). and when count will reach to >=20 it will put TIM3_CH1 to PWM Mode-1. and now pulses of 40KHz will start. and it works Ok. times of first pulse varies from 450us to 500 us but OK.

The input can be of UPTO 1200Hz freq.

My problem is that what I have done here is for 1 I/O set.

like this I have 5 I/O sets. each have to work like above. 4 Output  will share TIM3 (TIM3_CH1, TIM3_CH2....) and fifth channel will use different Timer.

I can do this same for these 5 I/O sets. but because of it check for CCxIF bit in main function in polling mode and count for 20 pulses to go. it creates problem in timing of first pulse if any interrupt comes. (it is ok from 450us to 500us but not out of it) .

Can DMA help here, can DMA perform this task that it checks 20 times of CCxIF bit and then generate a interrupt, actually I have never worked on DMA so don't know about it or any other suggestion.

You can find my code in attachment for 1 I/O set.

null
    This topic has been closed for replies.

    7 replies

    waclawek.jan
    Super User
    May 3, 2018
    Posted on May 03, 2018 at 22:58

    I'd do everything in the timer update interrupt. I even wouldn't set up the EXTI interrupt - even if short pulses have to be catched, it's enough to read the status register of it in that timer interrupt.

    However, running an 'F030 at 8MHz this sounds to be an impossible task - that's only 200 machine cycles per 25us timer cycle, and I doubt two channels could be handled in that timeframe, not four, plus the fifth at a different timer, competing for the machine time.

    DMA migh help you with one channel but not four or five, the 'F030 simply does not have the resources for that.

    I'd reconsider your requirements. Is the low system clock necessary?

    JW

    sanju
    sanjuAuthor
    Associate III
    May 4, 2018
    Posted on May 04, 2018 at 05:27

    I can run the CPU at 48MHz by applying  PLL on internal oscillator. That's will make 1200 machine cycles in 25us time frame.

    here is one change I have to use three Timers (TIM3->CH1,CH2 , TIM15->CH1,CH2, TIM17->CH1) for PWM

    so you wants to say that I should configure TIM3 , TIM15 and TIM17 for 40KHz signal.

    and put only TIM3 to generate interrupt at every update.

    then I have to check each of five input pin status PORTx->IDR In this ISR one by one and perform their corresponding action for each. This should be complete in less than 1200 cycles for all 5 inputs.

    am I right?

    waclawek.jan
    Super User
    May 4, 2018
    Posted on May 04, 2018 at 07:36

    I would handle each channel in its respective timers' interrupt.

    JW