PWM using decade counter

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
sapan
Posts: 56
Joined: Sat Dec 24, 2011 1:22 pm

PWM using decade counter

Post by sapan »

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
User avatar
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

Post by Giovanni »

Please provide more info because I am not sure to understand what you want to do :-)

Giovanni
sapan
Posts: 56
Joined: Sat Dec 24, 2011 1:22 pm

Re: PWM using decade counter

Post by sapan »

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
PWM using decade counter.png (62.17 KiB) Viewed 7095 times
User avatar
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

Post by Giovanni »

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
sapan
Posts: 56
Joined: Sat Dec 24, 2011 1:22 pm

Re: PWM using decade counter

Post by sapan »

ok..thanks...will design the new hardware with this thing in mind...:)
User avatar
barthess
Posts: 861
Joined: Wed Dec 08, 2010 7:55 pm
Been thanked: 7 times

Re: PWM using decade counter

Post by barthess »

hi sapan,
Probably, trick can be done using DMA loading new value from memory each time counter finish to count.
joaquin
Posts: 49
Joined: Sat Jan 22, 2011 8:44 pm
Has thanked: 1 time
Been thanked: 3 times

Re: PWM using decade counter

Post by joaquin »

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).
sapan
Posts: 56
Joined: Sat Dec 24, 2011 1:22 pm

Re: PWM using decade counter

Post by sapan »

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.
manton
Posts: 6
Joined: Thu May 24, 2012 10:18 pm

Re: PWM using decade counter

Post by manton »

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.
Post Reply