My goal is to measure a sensor frequency in between 50kHz to 120kHz for a high resolution. As the first step I want to divide this frequency to be able for handle on the LPC111x.
Therefore I am using that signal as an external input on PIO3_5 to the Timer/counter using the Timer/Counter setup:
LPC_IOCON->PIO3_5 = (LPC_IOCON->PIO3_5 & ~(0x3FF)) | 0x21; //set up pin (sec 7.4.17) (no pull up, Hyst enable)
LPC_SYSCON->SYSAHBCLKCTRL |= (1<<7)|(1<<16)|(1<<6); //enable clock signal CT16B0 (sec 3.5.14)
LPC_TMR16B0 ->PR = 0; //no preclear (sec 18.7.4)
LPC_TMR16B0 ->MR0 = 200; //compare-counter(sec 18.7.7)
LPC_TMR16B0 ->MR1 = 0;
LPC_TMR16B0 ->MCR = 0x03; //TC Reset on MR0 Match, enable Interrupt (sec 18.7.6)
LPC_TMR16B0->EMR = 0x30; //do nothing (sec 18.7.10)
LPC_TMR16B0 ->PWMC = 0; //no PWM Mode, (sec 18.7.12)
LPC_TMR16B0 ->CTCR = 05; // (sec 18.7.11) counter mode on rising edge, CT16Bn_CAP0
LPC_TMR16B0 ->TCR = 02; //reset (sec 18.7.2)
LPC_TMR16B0 ->TCR = 01; //GO (sec 18.7.2)
For the first test I am reading in a polling loop the LPC_TMR16B0->TC and expecting random values, but getting just zero.
I am not going to use the Capture.
May be I am not understanding some basics in using the external Counter input.
Hi Bernd,
You are using the wrong input pin.
From your code, I can find you are using TMR16B0, but PIO3_5 is the CT16B1_CAP1 pin.
So, actually you can use the PIO3_4 pin, this is the CT16B0_CAP1 pin.
Please modify the pin, and try again, I suggest you enable the internal pull up resistor.
Wish it helps you!
If you still have question about it, please kindly let me know.
Have a great day,
Kerry
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
I am sorry for my delay, was out for 2 weeks.
I have changed the pin and setup as recommended, but the getting the same result.
I also can read the toggling pin 3_4.
Are there some other suggestions?
Best Regards
Hi bernd,
Thanks for your updated information.
Do you debug your code, when you input the toggle wave to pin 3_4, check the timer counter, whether it can counter?
If no, please share me your project, I will help you to check it in my side.
Have a great day,
Kerry
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Hi Kerry,
thank for the real fast answer.
here is the extract of my from the priject:
void initCTR() // Sensor-input 50...120kHz
----------------------------------------------------------------------------------------------------------
#define DYN_STAND (3,4)
{
LPC_IOCON->PIO3_4 = (LPC_IOCON->PIO3_4 & ~(0x3FF)) | 0x21; //set up pin (sec 7.4.17) (no pull up, Hyst enable)
LPC_SYSCON->SYSAHBCLKCTRL |= (1<<7)|(1<<16)|(1<<6); //enable clock signal CT16B1 (sec 3.5.14)
LPC_TMR16B0 ->PR = 0; //no prescaler (sec 18.7.4)
LPC_TMR16B0 ->MR0 = 200; //compare-counter(sec 18.7.7)
LPC_TMR16B0 ->MR1 = 0; //
LPC_TMR16B0 ->MCR = 0x03; //TC Reset on MR0 Match, enable Interrupt (sec 18.7.6)
LPC_TMR16B0 ->EMR = 0x30; //do nothing (sec 18.7.10)
LPC_TMR16B0 ->PWMC = 0; //no PWM Mode, (sec 18.7.12)
LPC_TMR16B0 ->CTCR = 05; // (sec 18.7.11) counter mode on rising edge, CT16Bn_CAP1
// LPC_TMR16B0 ->CCR = 00; // (sec 19.7.8)
LPC_TMR16B0 ->TCR = 02; //reset (sec 18.7.2)
LPC_TMR16B0 ->TCR = 01; //GO (sec 18.7.2)
}
void TIMER16_0_IRQHandler(void)
{
LPC_TMR16B0->IR = (1<<0); //Clear MR0 Interrupt flag
if (GPIOGetValue DYN_STAND == 1) GPIOSetValue TestPin;
else GPIOclrValue TestPin;
return;
}
............
initCTR();
NVIC_EnableIRQ(TIMER_16_0_IRQn);
.........
loop for
sprintf(String,"Count: %04X %1X",LPC_TMR16B0->TC, GPIOGetValue DYN_STAND);
Print(String);
............
-----------------------------------------------------------------------------------------------------------
On sys system the TMR16B1 is running perfect a PWM used for a back light.
Best regards
Hi Bernd,
Just attach the project, you can delete all the other important code to you.
Just leave the problem timer code, then I can test it directly on my side.
Please also tell me your LPC111x full name.
Have a great day,
Kerry
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Hi Kerry,
It is an existing more complex project in which we just to make an add-on. So it is not so easy to cut off the rest.
The whole attachment I did you already have got.
The processor is a LPC1115/303 using a low clock (3.6864) to prevent RF-interference.
To measure the wanted frequency we have to divide it first to be able to handle it with the processor.
The first step of my intention was just to make that divider using the TMR16B0.
After that I may use the TMR32Bx as well.
Best regards
Bernd
Hi bernd,
OK, I will test it on my side, please give me more time.
After I test it, I will let you know.
Please wait patiently, thanks.
Have a great day,
Kerry
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Hi Kerry,
just to remember, do you need more time?
Regards Bernd