cancel
Showing results for 
Search instead for 
Did you mean: 

Using STR730 Timers to count pulses?

jalenius
Associate
Posted on February 06, 2006 at 10:07

Using STR730 Timers to count pulses?

6 REPLIES 6
jalenius
Associate
Posted on January 27, 2006 at 18:21

Hi i am new to ARM CPUs and i was wondering if it is possible to use any of the timers as counters using the EXTCLK.

I wnat to count puslses that vary betveen 0 and 1khz.

Is this possible?

And if it is where do i connect the in signal? can not find any thing interesting on EXTCLK.

tech9
Associate II
Posted on January 30, 2006 at 10:59

Hi Matte,

I use the STR710 and it has 4 timers, but only 2 of them can be used as a counter with an external clock event. (the first, and the third, same also with the STR711)

Check the lines below:

// Initialize the Timer 1

TIM_Init ( TIM1 );

TIM_ClockSourceConfig ( TIM1, TIM_EXTERNAL ); // set the last bit in CR1...

TIM_ClockLevelConfig ( TIM1, TIM_FALLING ); // clear the 2nd last bit in CR1

// Start the Counter

TIM_CounterConfig ( TIM1, TIM_START );

// Initialize the Timer 3

TIM_Init ( TIM3 );

TIM_ClockSourceConfig ( TIM3, TIM_EXTERNAL ); // set the last bit in CR1...

TIM_ClockLevelConfig ( TIM3, TIM_FALLING ); // clear the 2nd last bit in CR1

// Start the Counter

TIM_CounterConfig ( TIM3, TIM_START );

You can check the values in the counters with:

value3=TIM3->CNTR;

value1=TIM1->CNTR;

I've read values (in pulses) with frequencies exceeding 20 kHz, without missing a single beat.

Pins are configured as:

GPIO_Config (GPIO1, 0x0010, GPIO_INOUT_WP); //pin 1.4, extclk timer 1

GPIO_Config (GPIO1, 0x0002, GPIO_INOUT_WP); //pin 1.1, extclk timer 3

Hope this helps!

Best regards

Jp

mohamed23
Associate II
Posted on February 02, 2006 at 15:11

Hi Matte809,

This is very easy, You can simply connect your external Pulse clock to any STR73x Input Capture Pin (12 or 20 depending on the package 144pin or 100pin ) and use the related timer on its Input capture Mode. I recommand you to download the STR73x Standard library software and try to use directely the TIM (Timer)example then tailor it to suit your need.

With kind Regards :D

[ This message was edited by: Rave on 02-02-2006 19:45 ]

ivanla
Associate
Posted on February 04, 2006 at 07:53

Hi!

I'm trying to do the same thing but I have a hard time doing it.

I have checked through both the reference and library manual many times now (including checked the internal library functions) and my code seems to do what is supposed to be done to get it working, but it is not working.

Im sending in a square wave form signal at 20Hz on the ICAPA4 (port 1.3 on the board im using) but the interrupt just doesnt trigger.

I have tried just by polling the port to see if i get any signal, and that I get.

I have got TIM to work with MCLK and external Fext but not via the ICAPA pins.

This is the code im using:

/* Clock Config CMU, sets the CMU to use the main osc. 4MHz */

CMU_InitStructure.CMU_RCOscControl = 0xD;

CMU_InitStructure.CMU_EndCountValue = 0xF;

CMU_InitStructure.CMU_FreqRef_High = 0xFF;

CMU_InitStructure.CMU_FreqRef_Low = 0xFE;

CMU_InitStructure.CMU_CKSEL0 = CMU_CKSEL0_CKOSC;

CMU_InitStructure.CMU_CKSEL1 = CMU_CKSEL1_CKOSC;

CMU_InitStructure.CMU_CKSEL2 = CMU_CKSEL2_CKOSC;

CMU_Init(&CMU_InitStructure);

/* Clock Config PRCCU, MCLK = main osc * 5 = 20MHz */

PRCCU_DeInit();

PRCCU_InitStructure.PRCCU_DIV2 = DISABLE;

PRCCU_InitStructure.PRCCU_PLLDIV = PRCCU_PLLDIV_4;

PRCCU_InitStructure.PRCCU_PLLMUL = PRCCU_PLLMUL_20;

PRCCU_InitStructure.PRCCU_MCLKSRC_SRC = PRCCU_MCLKSRC_PLL;

PRCCU_InitStructure.PRCCU_FREEN = DISABLE;

PRCCU_Init (&PRCCU_InitStructure);

/* Clock Enable */

CFG_PeripheralClockConfig(CFG_CLK_GPIO1, ENABLE);

CFG_PeripheralClockConfig(CFG_CLK_EIC, ENABLE);

CFG_PeripheralClockConfig(CFG_CLK_TIM5, ENABLE);

/* GPIO1 Configuration */

GPIO1_InitStructure.GPIO_Mode = GPIO_Mode_IN_TRI_TTL;

GPIO1_InitStructure.GPIO_Pins = GPIO_PIN_3;

GPIO_Init (GPIO1, &GPIO1_InitStructure);

/*EIC Configuration, Im using a TB timer also thats why its there. It been cut out to save space on the post */

EIC_InitStructure.EIC_IRQChannel = TB0_IRQChannel;

EIC_InitStructure.EIC_FIQChannel = TIM0_FIQChannel;

EIC_InitStructure.EIC_IRQCmd = ENABLE;

EIC_InitStructure.EIC_FIQCmd = DISABLE;

EIC_InitStructure.EIC_IRQChannelPriority = 1;

EIC_Init (&EIC_InitStructure);

EIC_IRQChannelConfig(TIM5_IRQChannel, ENABLE );

EIC_IRQChannelPriorityConfig(TIM5_IRQChannel,2);

/*Timer Configuration 5 Klocka = Givarens pulser*/

TIM_InitStructure.TIM_Clock_Source = TIM_ICAP_4;

TIM_InitStructure.TIM_Clock_Edge = TIM_Rising;

TIM_InitStructure.TIM_Mode = TIM_OPM;

TIM_InitStructure.TIM_ICAPA_Modes = TIM_Rising;

TIM_InitStructure.TIM_Pulse_Level_A = TIM_High;

TIM_Init (TIM5, &TIM_InitStructure);

/* Enable Interrupts */

TB_ITConfig (TB0,ENABLE);

TB_Cmd(TB0, ENABLE);

TIM_ITConfig (TIM5, TIM_IT_TO, ENABLE);

TIM_CounterCmd(TIM5, TIM_START);

EIC_IRQCmd(ENABLE);

What I want it to do is to trigger interrupt on overflow.

[ This message was edited by: Fuel on 04-02-2006 12:26 ]

[ This message was edited by: Fuel on 05-02-2006 11:18 ]

feten
Associate
Posted on February 06, 2006 at 04:25

Hi,

I have some remarks about your code:

1/ You are using TIM5, so you have to configure the corresponding IC(ICAPA5 not ICAPA4).

2/ Enable the GPIO0 clock and not the GPIO1.

3/ If you want to use the TIM5 to measure an external signal, you have to precise this mode in the ''TIM_InitStructure.TIM_Mode'' and you ca use the following configuration:

/* TIM configuration in Input Capture Mode */

TIM_InitStructure.TIM_Mode = TIM_ICAP_CHANNELA;

TIM_InitStructure.TIM_Clock_Source = TIM_CLK_INTERNAL;

TIM_InitStructure.TIM_Prescaler = 0xFF; /* you can adjust this value */

TIM_InitStructure.TIM_ICAPA_Modes = TIM_Falling;

TIM_Init (TIM5, &TIM_InitStructure);

4/ If you have to configure the TIM5 in One Pulse Mode(OPM), you have to use the following configuration:

/* TIM configuration in OPM */

TIM_InitStructure.TIM_Mode = TIM_OPM;

TIM_InitStructure.TIM_Pulse_Level_A = TIM_High ;

TIM_InitStructure.TIM_Clock_Source = TIM_CLK_INTERNAL;

TIM_InitStructure.TIM_Period_Level = TIM_Low;

TIM_InitStructure.TIM_Prescaler = 0xFF;

TIM_InitStructure.TIM_Pulse_Length_A = 0xFF0;/* Can be adjusted*/

TIM_InitStructure.TIM_INPUT_Edge = TIM_Rising;

TIM_Init (TIM5, &TIM_InitStructure);

Feten.

ivanla
Associate
Posted on February 06, 2006 at 10:07

Hi!

Thank you for your information.

Although I wanted to use the ICAPA pin as a clock, and nothing else. I have however solved this now, it seems as you said that TIM5 must use TIM_ICAP_5, so I changed TIM5 to TIM4 and now it works.

Code::

TIM_DeInit(TIM4);

TIM_InitStructure.TIM_Clock_Source = TIM_ICAP_4;

TIM_Init (TIM4, &TIM_InitStructure);

TIM_ITConfig (TIM4, TIM_IT_TO, ENABLE);

/* Enable interrupts */

EIC_IRQCmd(ENABLE);

TIM_CounterCmd(TIM4, TIM_START);