Test and Measurement Forum

Counting pulses generated by Picoscope

Post general discussions on using our drivers to write your own software here

Counting pulses generated by Picoscope

Postby Pwillbasoon » Wed Dec 20, 2017 3:42 am

I want to count the pulses which is generated by Picoscope using STM32f407VG kynix.com/Detail/374092/STM32F407VGT6.html my signal frequency is (20Hz)
I used the timer2, the problem is that the counter increment to 1 and came back to 0, I don't understand why ??? since it must increment every 50ms.
4aYmQ.png


I devellopped the code show bellow :
Code: Select all
#include "stm32f4xx.h"
#include "stm32f4xx_rcc.h"
#include "stm32f4xx_gpio.h"
#include "stm32f4xx_tim.h"

void GPIO_Init_TM(void);

int variable = 0;

int main(void)
{
  GPIO_Init_TM();
  while(1)
  {
    variable = TIM_GetCounter(TIM2);
  }
}

void GPIO_Init_TM(void)

{

RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);

RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);

GPIO_InitTypeDef gpioStructure;
//TIM_TimeBaseInitTypeDef timerInitStructure;

gpioStructure.GPIO_Pin = GPIO_Pin_15 ;
gpioStructure.GPIO_Mode = GPIO_Mode_AF;
gpioStructure.GPIO_PuPd = GPIO_PuPd_UP;

GPIO_Init(GPIOA, &gpioStructure);

GPIO_PinAFConfig(GPIOA, GPIO_PinSource15, GPIO_AF_TIM2);

TIM_EncoderInterfaceConfig(TIM2, TIM_EncoderMode_TI1,TIM_ICPolarity_Rising, TIM_ICPolarity_Rising );
TIM_SetAutoreload (TIM2, 0xffff);

TIM_Cmd(TIM2, ENABLE);
}


and this is the result I get :
NPa9C.png
Pwillbasoon
Newbie
 
Posts: 0
Joined: Wed Dec 20, 2017 3:25 am

Re: Counting pulses generated by Picoscope

Postby Martyn » Wed Dec 20, 2017 8:29 am

A quick thought, are you counting both the positive and negative halves of the waveform, an up down counter ?

For counting pulses you need to count just the rising edges.
Martyn
Technical Support Manager
Martyn
Site Admin
Site Admin
 
Posts: 2970
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots


Return to General Software Discussions

Who is online

Users browsing this forum: No registered users and 0 guests