Микроконтроллеры

Информация о пользователе

Привет, Гость! Войдите или зарегистрируйтесь.


Вы здесь » Микроконтроллеры » Архив » stm32 one pulse


stm32 one pulse

Сообщений 1 страница 9 из 9

1

Добрый день, необходимо генерировать одиночный импульс.

Код:
    RCC->AHBENR |= RCC_AHBENR_GPIOAEN;
    RCC->APB2ENR |= RCC_APB2ENR_TIM15EN;
    //PA2 push-pull
    GPIOA->MODER |= GPIO_MODER_MODER2_1;
    GPIOA->OSPEEDR |= GPIO_OSPEEDER_OSPEEDR2;
    GPIOA->PUPDR &= ~GPIO_PUPDR_PUPDR2;
    GPIOA->AFR[0] |= (0x09<<2*4);
    
    TIM15->PSC  = 7200 -1; 
    TIM15->ARR  = 700 - 1; 
    TIM15->CCR1 = 350 - 1;    
    
    TIM15->CR1 &= ~TIM_CR1_DIR; 
    TIM15->CR1 |= TIM_CR1_OPM; 
    TIM15->BDTR |= TIM_BDTR_MOE;
    
    TIM15->CCER |= TIM_CCER_CC1E;
    TIM15->CCMR1 = TIM_CCMR1_OC1M_1 | TIM_CCMR1_OC1M_2;//PWM
    TIM15->CR1  |= TIM_CR1_CEN;	

Подскажите, что делаю не так?

2

Извинявс что на котах не ответил.

А кто пинает таймер?
В примерах так:

2.6 Timer one pulse mode
One pulse mode (OPM) is a particular case of the input capture mode and the output
compare mode. It allows the counter to be started in response to a stimulus and to generate
a pulse with a programmable length after a programmable delay.
To configure the timer this mode:
1. Configure the input pin and mode:
a) Select the TIxFPx trigger to be used by writing CCxS bits in CCMRx register.
b) Select the polarity of the input pin by writing CCxP and CCxNP bits in CCER
register.
c) Configure the TIxFPx trigger for the slave mode trigger by writing TS bits in SMCR
register.
d) Select the trigger mode for the slave mode by writing SMS = 110 in SMCR
register.
2. Configure the output pin and mode:
a) Select the output polarity by writing CCyP bit in CCER register.
b) Select the output compare mode by writing OCyM bits in CCMRy register (PWM1
or PWM2 mode).
c) Set the delay value by writing in CCRy register.
d) Set the auto reload value to have the desired pulse: pulse = TIMy_ARR TIMy_CCRy.
3. Select the one pulse mode by setting the OPM bit in CR1 register, if only one pulse is to
be generated. Otherwise this bit should be reset.
Delay = CCRy/(TIMx_CLK/(PSC + 1))
Pulse-Length = (ARR - CCRy)/(TIMx_CLK/(PSC + 1))

И в сниппетсах:

Код:
__INLINE void ConfigureTIMxAsOPM(void)
{
  /* (1) Enable the peripheral clock of Timer x */
  /* (2) Enable the peripheral clock of GPIOA and GPIOB*/
  /* (3) Select alternate function mode on GPIOA pin 15 */
  /* (4) Select AF2 on PA15 in AFRH for TIM2_CH1 */
  /* (5) Select alternate function mode on GPIOB pin 3 */
  /* (6) Select AF2 on PB3 in AFRL for TIM2_CH2 */
  
  RCC->APB1ENR |= RCC_APB1ENR_TIM2EN; /* (1) */
  RCC->AHBENR |= RCC_AHBENR_GPIOAEN | RCC_AHBENR_GPIOBEN; /* (2) */  
  GPIOA->MODER = (GPIOA->MODER & ~(GPIO_MODER_MODER15)) | (GPIO_MODER_MODER15_1); /* (3) */
  GPIOA->AFR[1] |= 0x02 << ((15 - 8) *4); /* (4) */
  GPIOB->MODER = (GPIOB->MODER & ~(GPIO_MODER_MODER3)) | (GPIO_MODER_MODER3_1); /* (5) */
  GPIOB->AFR[0] |= 0x02 << (3 * 4); /* (6) */
  
  /* Use TI2FP2 as trigger 1 */
  /* (1) Map TI2FP2 on TI2 by writing CC2S=01 in the TIMx_CCMR1 register */
  /* (2) TI2FP2 must detect a rising edge, write CC2P=0 and CC2NP=0 
         in the TIMx_CCER register (keep the reset value) */
  /* (3) Configure TI2FP2 as trigger for the slave mode controller (TRGI) 
         by writing TS=110 in the TIMx_SMCR register 
         TI2FP2 is used to start the counter by writing SMS to ‘110' 
         in the TIMx_SMCR register (trigger mode) */
  TIMx->CCMR1 |= TIM_CCMR1_CC2S_0; /* (1) */
  //TIMx->CCER &= ~(TIM_CCER_CC2P | TIM_CCER_CC2NP); /* (2) */
  TIMx->SMCR |= TIM_SMCR_TS_2 | TIM_SMCR_TS_1 
              | TIM_SMCR_SMS_2 | TIM_SMCR_SMS_1; /* (3) */
  
  /* The OPM waveform is defined by writing the compare registers */
  /* (1) Set prescaler to 47, so APBCLK/48 i.e 1MHz */ 
  /* (2) Set ARR = 7, as timer clock is 1MHz the period is 8 us */
  /* (3) Set CCRx = 5, the burst will be delayed for 5 us (must be > 0)*/
  /* (4) Select PWM mode 2 on OC1  (OC1M = 111),
         enable preload register on OC1 (OC1PE = 1, reset value) 
         enable fast enable (no delay) if PULSE_WITHOUT_DELAY is set*/
  /* (5) Select active high polarity on OC1 (CC1P = 0, reset value),
         enable the output on OC1 (CC1E = 1)*/
  /* (6) Enable output (MOE = 1)*/
  /* (7) Write '1 in the OPM bit in the TIMx_CR1 register to stop the counter 
         at the next update event (OPM = 1)
         enable auto-reload register(ARPE = 1) */  
  
  TIMx->PSC = 47; /* (1) */
  TIMx->ARR = 7; /* (2) */
  TIMx->CCR1 = 5; /* (3) */
  TIMx->CCMR1 |= TIM_CCMR1_OC1M_2 | TIM_CCMR1_OC1M_1 | TIM_CCMR1_OC1M_0 
               | TIM_CCMR1_OC1PE 
#if PULSE_WITHOUT_DELAY > 0
               | TIM_CCMR1_OC1FE
#endif                 
               ; /* (4) */
  TIMx->CCER |= TIM_CCER_CC1E; /* (5) */
  TIMx->BDTR |= TIM_BDTR_MOE; /* (6) */
  TIMx->CR1 |= TIM_CR1_OPM | TIM_CR1_ARPE; /* (7) */
}



3

свои варианты на F1 я тут выкладывал TIM1 и TIM4 One Pulse Mode (STM32F103)

4

У меня нет внешнего сигнала, хотел бы пинать его вручную.
Подскажите как это  сделать?

Подскажите пожалуйста откуда Вы взяли снипетс?

Еще вопрос, что значит стрелочка?
http://prntscr.com/l7zg4y

Отредактировано qasta (2018-10-19 17:32:42)

5

Так посмотри как у Atomic-dm сделано, триггер же не обязательно внешний должен быть...
Сниппетсы от F0 и без разницы что от F0, таймеры то одинаковые.
Стрелочка прерывание от триггера.

6

я так понимаю под внутренним сигналом подразумевается itr, то есть это выходной сигнал TRGO другого таймера. А нельзя ли обойтись одним таймером и как-то вручную запускать?
http://prntscr.com/l81moh

Отредактировано qasta (2018-10-20 01:59:00)

7

Генерим 5 импульсов - период 100mS, длина 40mS . В RCR количество импульсов.

Код:
#define PERIOD 100
#define PULSE 40
#define PULSE_NUMBER  5
	
uint16_t Prescaler;
	
RCC->AHBENR |= RCC_AHBENR_GPIOAEN;
GPIOA->MODER &= ~( GPIO_MODER_MODER8); 
GPIOA->MODER |=  GPIO_MODER_MODER8_1 ; 
GPIOA->AFR[1] |=(2<<(4*0));
	
RCC->APB2ENR |= RCC_APB2ENR_TIM1EN; /* Peripheral clock enable */
Prescaler = (uint16_t) (SystemCoreClock / 1000000) - 1;

TIM1->ARR = PERIOD-1; /* Set the Autoreload value */
TIM1->CCR1 = PULSE; /* Set the Pulse value */
TIM1->PSC = Prescaler; /* Set the Prescaler value */
TIM1->RCR = PULSE_NUMBER - 1; /* Set the Repetition counter value */
TIM1->EGR = TIM_EGR_UG; /* Generate an update event to reload the Prescaler
                            and the repetition counter value immediately */
	
TIM1->SMCR = RESET; /* Configure the Internal Clock source */
TIM1->CR1 |= TIM_CR1_OPM; /* Select the OPM Mode */


TIM1->CCMR1=TIM_CCMR1_OC1M_2 |TIM_CCMR1_OC1M_1 |TIM_CCMR1_OC1M_0 |TIM_CCMR1_OC1PE;



TIM1->CCER = TIM_CCER_CC1E ; /* Enable the Compare output channel 1 */
TIM1->BDTR |= TIM_BDTR_MOE; /* Enable the TIM main Output */
TIM1->CR1 |= TIM_CR1_CEN; /* Enable the TIM peripheral */

8

Ну и на будущее - General-purpose timer cookbook
https://www.stmicroelectronics.com.cn/c … 236305.pdf

Сниппетсы     https://www.st.com/en/embedded-software … etsf0.html

9

СПАСИБО!!!dosikus

Отредактировано qasta (2018-10-22 17:04:32)


Вы здесь » Микроконтроллеры » Архив » stm32 one pulse