lpcware

Total Noob needs a small push - interrupt pulse length counter displayed on Uart.

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by Wenzu on Sun Dec 19 06:11:55 MST 2010
Hi, Season's greetings to all.

I'm coming from PIC 18F and 24F background, also Arduino.
I am used to code in Basic, using varius IDE's. Familiar and also comfortable with C.

I have just purchased an LPCExpresso 1343 board because I am forseeing that my next projects need all horsepower that this part can provide. I have tried the provided examples in Develop. All work fine.

However, it is my impression that the way to work with what happens during interrupt vectors is not shown in these examples.

What I'm trying to do as a first step is to measure a PWM coming from a signal generator's square wave output ( limited to 3.3Volts output ) into Port2.1, and at first, switching the LED ( Port0.7) in sync with this.
Then I've added the Uart to let me know my connections are OK. Whatever I type is echoed back. This works fine.
Then I tried adding a Timer to count the High pulse, and also derive the period of the incoming PWM, and this is where I failed miserably. ( I have removed the offending and non working code.. out of shyness :)

[SIZE=2][COLOR=#7f0055]

[B][SIZE=2][COLOR=#7f0055]#include
[/COLOR][/SIZE][/B][/COLOR][/SIZE][LEFT][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"LPC13xx.h"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]/* LPC13xx Peripheral Registers */[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#3f7f5f]
[LEFT][/COLOR][/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]#include[/LEFT]
[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][/B][LEFT][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"gpio.h"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#2a00ff]
[LEFT][/COLOR][/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]#include[/LEFT]
[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][/B][LEFT][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"uart.h"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#2a00ff]
[LEFT][/COLOR][/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]#include[/LEFT]
[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][/B][LEFT][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"config.h"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#2a00ff]
[/COLOR][/SIZE]
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]extern[/LEFT]
[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][/B][LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]volatile[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2][COLOR=#005032][SIZE=2][COLOR=#005032]uint32_t[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] UARTCount;[/SIZE]
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]extern[/LEFT]
[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][/B][LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]volatile[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2][COLOR=#005032][SIZE=2][COLOR=#005032]uint8_t[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] UARTBuffer[BUFSIZE];[/SIZE]

[LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]/*****************************************************************************[/COLOR][/SIZE]
[SIZE=2][COLOR=#3f7f5f]** Main Function main()[/COLOR][/SIZE]
[SIZE=2][COLOR=#3f7f5f]******************************************************************************/[/COLOR][/SIZE]
[/COLOR][/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/LEFT]
[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][/B][LEFT][SIZE=2][B]main[/B] ([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2])[/SIZE]
[LEFT][SIZE=2]{[/SIZE][/LEFT]

[LEFT][SIZE=2]UARTInit(115200);[/SIZE]
[SIZE=2]GPIOInit();[/SIZE]
[SIZE=2]GPIOSetDir( PORT2, 1, 0 );[/SIZE]
[SIZE=2]GPIOSetInterrupt( PORT2, 1, 0, 1, 1 );[/SIZE][/LEFT]

[LEFT][SIZE=2]GPIOIntEnable( PORT2, 1 );[/SIZE][/LEFT]

[LEFT][SIZE=2]GPIOSetDir( LED_PORT, LED_BIT, 1 );[/SIZE]
[SIZE=2]GPIOSetValue( LED_PORT, LED_BIT, LED_OFF );[/SIZE][/LEFT]

[LEFT][SIZE=2][U]UARTSend([/U][/SIZE][U][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"Pulse Length Counter"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], 20);[/SIZE][/U][/LEFT]

[LEFT][SIZE=2] [/SIZE]
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]while[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] (1)[/SIZE]
[SIZE=2]{[/SIZE]
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]if[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] ( UARTCount != 0 ) [/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]// whatever I type in Hyper terminal is echoed back.[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#3f7f5f]
[/COLOR][/SIZE][SIZE=2]{[/SIZE]
[SIZE=2]LPC_UART->[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]IER[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = IER_THRE | IER_RLS; [/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]/* Disable RBR */[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#3f7f5f]
[/COLOR][/SIZE][SIZE=2]UARTSend( ([/LEFT]
[/LEFT]
[/SIZE][LEFT][SIZE=2][COLOR=#005032][SIZE=2][COLOR=#005032]uint8_t[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] *)UARTBuffer, UARTCount );[/SIZE]
[LEFT][SIZE=2]UARTCount = 0;[/SIZE]
[SIZE=2]LPC_UART->[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]IER[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = IER_THRE | IER_RLS | IER_RBR; [/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]/* Re-enable RBR */[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#3f7f5f]
[/COLOR][/SIZE][SIZE=2]}[/SIZE]
[SIZE=2]}[/SIZE]
[SIZE=2]}[/SIZE][/LEFT]

[LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]/*********************************************************************************[/COLOR][/SIZE]
[SIZE=2][COLOR=#3f7f5f]** End Of File[/COLOR][/SIZE]
[SIZE=2][COLOR=#3f7f5f]*********************************************************************************/[/COLOR][/SIZE][/LEFT]
[/COLOR][/SIZE]


What I would like, is for some pointers to the right direction, in what I would like to achieve as a first step as mentioned above.

Thanks !!
[/LEFT]

Outcomes