Capture a square signal and treatment

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Capture a square signal and treatment

232 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by dreamway77 on Mon Nov 22 07:59:24 MST 2010
Hi!

I'm starting with NXP LPCxpresso 1114 and i need your help. It's my first time with µC. I would like to capture a square signal and define his period. Having defined this period, i would like to multiply by five. After that, i would like to out this new square signal.

First : What input use?
two : i do not know how to declare input and what init i do. Same for output.

Thanks for your help and i really need you.
0 Kudos
4 Replies

215 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Mon Nov 22 14:35:05 MST 2010
This LPC11C14 code is working with Timer1 & PIO_1.0 (PIN33) capture interrupt.
#define CT32B1 10
[LEFT]volatile unsigned int timer32_1_val = 0;
volatile unsigned char timer_32_event =0;[/LEFT]
 
[LEFT]void TIMER32_1_IRQHandler(void)
{
LPC_TMR32B1->IR = (1<<4);   //reset capture 0 interrupt 
LPC_TMR32B1->TC = 0;           //reset timer
timer32_1_val = LPC_TMR32B1->CR0; //get capture value
timer_32_event =1; //set flag
}[/LEFT]
 
[LEFT]int main(void)
{
....
LPC_SYSCON->SYSAHBCLKCTRL |= (1<<CT32B1); //power up Timer1/32
LPC_IOCON->R_PIO1_0 &= ~0x07; //clear
LPC_IOCON->R_PIO1_0 |= 0x03; //capture 0 & no pullup
LPC_TMR32B1->CCR = 0x05; //rising edge & interrupt 
NVIC_EnableIRQ(TIMER_32_1_IRQn); //enable int
LPC_TMR32B1->TCR = 1; //start timer[/LEFT]
 
 while(1)   //loop
 {
[LEFT] if(timer_32_event) //capture interrupt?
 {
  timer_32_event =0; //reset flag
  LED2_TOG; //scope out
 }[/LEFT]
.... 


With timer32_1_val input frequence can be calculated via:

frequence = Main Clock / timer32_1_val
0 Kudos

215 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Mon Nov 22 11:47:12 MST 2010
Did you read

http://knowledgebase.nxp.com/showthread.php?p=3961
0 Kudos

215 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by dreamway77 on Mon Nov 22 11:32:15 MST 2010
First thx for your response!

But my input square signal evolves constantly. The period varies. For multiply correctly i must define a new period value all the time!
It's not better to use input capture? and how to use there?

Thx.
0 Kudos

215 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by WhyNot on Mon Nov 22 09:53:24 MST 2010
Hi dreamway77,

You can read in the user manual the chapter of GPIO or Pin initialization.

you can use any of the GPIO Pins for  INPUT/OUTPUT  I advise you to use Port2/3 as some pins for Port1 are for JTAG and you can't reprogram your board afterwards....

some tips are

LPC_GPIOn->DIR  |= (1<<6) ; this piece of code would assing the bit 6 of Portn as an output (write a logic 1 to the DIR of port pin)

LPC_GPIOn->DIR &=~(1<<6); this would assign Pin6 of portn as an input (writes logic 0 to de DIR of port pin).

To read or write DATA to the port you can use   LPC_GPIOn->DATA = 1<<6  this will put value High in Portn.6 if its assigned as output and the DATA register will hold the state of the port that is Input....

So this should get you started.

Try to turn on and off the LED in the Board by reading the square wave.

There's good info on the examples.... good lucj
0 Kudos