Hi,
I am using decade counter to generate output for six servo. My question is can I use advance timers (timer 1 or 8) to load value of all the servo outputs into some registers so that they will automatically change without any software intervention.
Sapan
PWM using decade counter
Moderators: RoccoMarco, lbednarz, tfAteba
- Giovanni
- Site Admin
- Posts: 14892
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 996 times
Re: PWM using decade counter
Please provide more info because I am not sure to understand what you want to do 
Giovanni
Giovanni
Re: PWM using decade counter
Ok..Refer to figure attached. I want to generate output as shown by "Timer Output" (First Signal). Here it is generating pulses at predefined time interval t1,t2,t3,t4,t5,t6 at interval of 20 ms. My question is can I load values of t1 to t6 in some registers once every 20 ms so that it generates these pulses automatically?
- Attachments
-
- PWM using decade counter.png (62.17 KiB) Viewed 7095 times
- Giovanni
- Site Admin
- Posts: 14892
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 996 times
Re: PWM using decade counter
I think it is not possible to do that purely in hardware (I could be wrong), you may use the PWM driver to generate pulses changing the period on each falling edge (this way the change is effective in next cycle).
Giovanni
Giovanni
Re: PWM using decade counter
hi sapan,
Probably, trick can be done using DMA loading new value from memory each time counter finish to count.
Probably, trick can be done using DMA loading new value from memory each time counter finish to count.
Re: PWM using decade counter
Sapan, just one point: to drive the servos you don't need that the pulses arises one after the other. Each servo only have to know just its own channel.
At least with the STM32 I think that there are multiples ways to do it (I still haven't played with PWM, but judging from the datasheet it has plenty of features).
At least with the STM32 I think that there are multiples ways to do it (I still haven't played with PWM, but judging from the datasheet it has plenty of features).
Re: PWM using decade counter
You are right. STM32 has plenty of PWM. I was just trying to optimize further so that using only one channel you can run more servo, that way you have rest of pins available for other functionality as well.
Re: PWM using decade counter
There is an example using DMA data to update TIM CCR from ST STM32F4 DSP lib. Maybe it could suit your requirement.
Code: Select all
/**
@page TIM_DMA TIM DMA example
@verbatim
******************** (C) COPYRIGHT 2011 STMicroelectronics *******************
* @file TIM/DMA/readme.txt
* @author MCD Application Team
* @version V1.0.0
* @date 30-September-2011
* @brief Description of the TIM DMA example.
******************************************************************************
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
* TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
* DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
* FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
* CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
******************************************************************************
@endverbatim
@par Example Description
This example provides a description of how to use DMA with TIM1 Update request
to transfer Data from memory to TIM1 Capture Compare Register3.
TIM1CLK = SystemCoreClock, Prescaler = 0, TIM1 counter clock = SystemCoreClock
SystemCoreClock is set to 168 MHz for STM32F4xx.
The objective is to configure TIM1 channel 3 to generate complementary PWM
signal with a frequency equal to 17.57 KHz:
- TIM1_Period = (SystemCoreClock / 17570) - 1
and a variable duty cycle that is changed by the DMA after a specific number of
Update DMA request.
The number of this repetitive requests is defined by the TIM1 Repetion counter,
each 3 Update Requests, the TIM1 Channel 3 Duty Cycle changes to the next new
value defined by the SRC_Buffer.