This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

PWM without DMA - to save current?

I am using an RTC to periodically kick off a PWM pulse train. This all works beautifully, but draws far more current than expected. From what I've read, this is because the EasyDMA draws over 1mA. I think I know the answer, but want to confirm: can I drive a PWM pulse train without using DMA? I have in mind an ISR which would update the compare registers instead of DMA. This post: https://devzone.nordicsemi.com/f/nordic-q-a/37941/how-to-define-and-use-adc-and-pwm-without-dma-on-nrf52832 indicates that this is not the case.

This is the configuration code for the PWM, and the code in the RTC ISR which starts it:

void StepperMotor::init_pwm()
{
// Enable the peripheral.
m_conf.pwmx->ENABLE = (PWM_ENABLE_ENABLE_Enabled << PWM_ENABLE_ENABLE_Pos);

// PWM configuration.
m_conf.pwmx->PRESCALER = PWM_PRESCALER_PRESCALER_DIV_1; // 16MHz;
m_conf.pwmx->MODE = PWM_MODE_UPDOWN_Up << PWM_MODE_UPDOWN_Pos;
m_conf.pwmx->COUNTERTOP = COUNTERTOP;
m_conf.pwmx->DECODER = (PWM_DECODER_LOAD_Common << PWM_DECODER_LOAD_Pos) |
(PWM_DECODER_MODE_RefreshCount << PWM_DECODER_MODE_Pos);

// Interrupts and shorts.
m_conf.pwmx->INTEN = 0;
m_conf.pwmx->SHORTS = PWM_SHORTS_LOOPSDONE_STOP_Msk | PWM_SHORTS_SEQEND0_STOP_Msk;

// Clear events we might rely on.
m_conf.pwmx->EVENTS_LOOPSDONE = 0;
m_conf.pwmx->EVENTS_SEQEND[0] = 0;
m_conf.pwmx->EVENTS_SEQEND[1] = 0;
m_conf.pwmx->EVENTS_STOPPED = 0;

// Set up the sequence for the PWM.
m_conf.pwmx->SEQ[0].PTR = reinterpret_cast<uint32_t>(&g_clockwise_driving[0]);
m_conf.pwmx->SEQ[0].CNT = sizeof(g_clockwise_driving) / sizeof(g_clockwise_driving[0]);
m_conf.pwmx->SEQ[0].REFRESH = 0;
m_conf.pwmx->SEQ[0].ENDDELAY = 0;

m_conf.pwmx->LOOP = 0;
}
void StepperMotor::rtc_isr()
{
...  
// Kick off the PWM sequence. The waveform is common to all four outputs. We are using
   // three of them for the seconds, minutes and hours hands.
m_conf.pwmx->TASKS_SEQSTART[0] = 1;
}

Thanks.

Al

Parents
  • Hi Al

    My colleague is correct in that you can't disable the DMA. As long as the PWM-peripheral runs, so does the DMA. You may use the low power DMA library to reduce the current draw significantly, but this will result in a less accurate DMA. Otherwise you will just have to turn off the PWM-peripheral whenever it isn't used to decrease the current consumption. I am sorry for the bad news.

    Best regards,

    Simon

Reply
  • Hi Al

    My colleague is correct in that you can't disable the DMA. As long as the PWM-peripheral runs, so does the DMA. You may use the low power DMA library to reduce the current draw significantly, but this will result in a less accurate DMA. Otherwise you will just have to turn off the PWM-peripheral whenever it isn't used to decrease the current consumption. I am sorry for the bad news.

    Best regards,

    Simon

Children
No Data
Related