hardware counters

28 Aug 2012

Hi there, I'm wondeirng if there is any way to use the hardware counters thaty are described on page 495 of the nxp lpc17xx user manaual ? I'm trying to combine accurately counting a freqeuency with an intermittent reading of a 1 wire sensor. Using the InterruptIn function to increment a count in software is not working as the timing delays built into the 1 wire library seem to be causing problems.

Is there and C access to the timer counter registers and their controls ?

all the best

Chris

06 Dec 2012

Hi chris,

I want the same thing: access to the hardware counters.

In the mbed compiler I see all kinds of things in the peripherals.h but no counters.

They exist, but the mbed team seems to avoid them.

For a beginning this may help: http://mbed.org/users/Yo_Robot/notebook/how-to-generate-a-pulse-train-output/#c4504

08 Dec 2012

Hi chris,

Possibly there are high level solutions to be found here: http://www.coocox.org/show_comp/TIMER/273.html The Component is there ready for download!

Overview

Timer provides a 32 bit Timer/Counter with a programmable 32 bit Prescaler,up to two 32 bit capture channels per timer, four 32 bit match registers, up to four external outputs corresponding to match registers. It supports Timer and Counter mode. Timer 2 brings out all four Match outputs. The TIMER component can be used to set I2C clock source, configure Timer/Counter mode, configure Timer Match/Capture features, configure Timer interrupt.

Edit: I think this is about the same: http://mbed.org/users/frank26080115/code/LPC1700CMSIS_Lib/docs/84d7747641aa/lpc17xx__timer_8c.html

11 Dec 2012

Hi,bellow is a simple code to set a pin(one of 8 possible)as hardware counter.

#include "mbed.h"
int main()
{

    //enable PCTIM1
    LPC_SC->PCONP|=(1<<0x2);

    //SET P1.18(LED1) as counter
    LPC_PINCON->PINSEL3|=((1<<4)|(1<<5));

    //configure counter
    LPC_TIM1->TCR   =0x2;//counter disable
    LPC_TIM1->CTCR  =0x1;//counter mode,increments on rising edges
    LPC_TIM1->PR    =0x0;//set prescaler
    LPC_TIM1->TCR   =0x1;//counter enable

    while(1) {
        wait(0.5);
        printf("Counter: %u\r\n",LPC_TIM1->TC);

    }
}
11 Dec 2012

Notice: on mbed p5,p6,p7,p8 (Func4) all the 4 MATch of counter2 are available (*)

http://mbed.org/users/Lerche/notebook/lpc1768-pin-functions/

(*)Read my comment about an error in the diagram: http://mbed.org/users/Lerche/notebook/lpc1768-pin-functions/?page=1#comment-1313

11 Dec 2012

For counter you must use capture pins(inputs),not match pins(outputs). On mbed p13(CAP3.0),p4(CAP3.1) and LED1(CAP1.0) are available

11 Dec 2012

Cosmin Buruleanu wrote:

For counter you must use capture pins(inputs),not match pins(outputs). On mbed p13(CAP3.0),p4(CAP3.1) and LED1(CAP1.0) are available

Well, it depends (I think). If you want to let your counter record external events then those events are taken up by the Capture pin. So CAP sends a signal from pin Into the counter (or its controls to start, stop, store its contents).

But I want to output a pulse if the counter arrives at an internal set value. For that it uses the MATch condition and the output pin will do something (toggle, go Low, go High). (I think MAT2.0, MAT2.1, MAT2.2 and MAT2.3 can do all the Step and Dir for 2 stepper motors) For my purpose I want these steps of the stepper motors at very precise moments: they must act as a pair. MAT-pin gets a signal Out of the counter at the set counter match value.

For my goals read this question+answers: http://mbed.org/questions/118/Why-are-counters-as-a-peripheral-avoided/