Timer and interrupts

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

Timer and interrupts

421 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ferix on Thu Jul 28 10:54:38 MST 2011
Hello

I want to dim a lot of LED's using Bit Angle Modulation.
In the blinky example, the uC goes into sleep mode after executing its code and once every 10mS the timer "Interrupts" and the uC wakes up, executes the blinkaled code and goes back to sleep.
I want to do other stuff to while PWMing LED's so i don't want to have my uC sleeping all the time.
How do i modify my code to do this:

  [FONT=Courier New, monospace][SIZE=2][COLOR=#7f0055][B]#include[/B][/COLOR][COLOR=#2a00ff]"driver_config.h"[/COLOR][/SIZE][/FONT]
 [FONT=Courier New, monospace][SIZE=2][COLOR=#7f0055][B]#include[/B][/COLOR][COLOR=#2a00ff]"target_config.h"[/COLOR][/SIZE][/FONT]
 [FONT=Courier New, monospace][SIZE=2][COLOR=#7f0055][B]#include[/B][/COLOR][COLOR=#2a00ff]"timer32.h"[/COLOR][/SIZE][/FONT]
 [FONT=Courier New, monospace][SIZE=2][COLOR=#7f0055][B]#include[/B][/COLOR][COLOR=#2a00ff]"gpio.h"[/COLOR][/SIZE][/FONT]
 

 [FONT=Courier New, monospace][SIZE=2][COLOR=#7f0055][B]int [/B][/COLOR][COLOR=#000000][B]main[/B][/COLOR][COLOR=#000000] ([/COLOR][COLOR=#7f0055][B]void[/B][/COLOR][COLOR=#000000])[/COLOR][/SIZE][/FONT]
 [COLOR=#000000][FONT=Courier New, monospace][SIZE=2]{[/SIZE][/FONT][/COLOR]
 [COLOR=#000000][FONT=Courier New, monospace][SIZE=2]init_timer32(1, TIME_INTERVAL);[/SIZE][/FONT][/COLOR]
 [COLOR=#000000][FONT=Courier New, monospace][SIZE=2]enable_timer32(1);[/SIZE][/FONT][/COLOR]
 [COLOR=#000000][FONT=Courier New, monospace][SIZE=2]GPIOInit();[/SIZE][/FONT][/COLOR]
 

 [FONT=Courier New, monospace][SIZE=2][COLOR=#7f0055][B]while[/B][/COLOR][COLOR=#000000](1)[/COLOR][/SIZE][/FONT]
   [COLOR=#000000][FONT=Courier New, monospace][SIZE=2]{[/SIZE][/FONT][/COLOR]
 [COLOR=#000000][FONT=Courier New, monospace][SIZE=2]    dostuffhere[/SIZE][/FONT][/COLOR]
   [COLOR=#000000][FONT=Courier New, monospace][SIZE=2]}[/SIZE][/FONT][/COLOR]
 [COLOR=#000000][FONT=Courier New, monospace][SIZE=2]}[/SIZE][/FONT][/COLOR]
 

 [COLOR=#000000][FONT=Courier New, monospace][SIZE=2]Timerinterrupt()[/SIZE][/FONT][/COLOR]
 [COLOR=#000000][FONT=Courier New, monospace][SIZE=2]{[/SIZE][/FONT][/COLOR]
 [COLOR=#000000][FONT=Courier New, monospace][SIZE=2]    Code for PWMing LED's with Bit Angle Modulation[/SIZE][/FONT][/COLOR]
 [COLOR=#000000][FONT=Courier New, monospace][SIZE=2]}[/SIZE][/FONT][/COLOR]
 
Its a bit of a beginners question but i hope you don't mind to help me out.
0 Kudos
4 Replies

402 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ferix on Thu Jul 28 14:43:45 MST 2011
hmm, i got something working
i still have this part of code:
Int test123 (void)
{
GPIOSetValue(0, 7, 1);
}
in the timer32.C library i found that every time the timer "interrupts" this part of code triggers.
void TIMER32_0_IRQHandler(void)
{  
  if ( LPC_TMR32B0->IR & 0x01 )
  {  
    LPC_TMR32B0->IR = 1;                /* clear interrupt flag */
    timer32_0_counter++;
  }
  if ( LPC_TMR32B0->IR & (0x1<<4) )
  {  
    LPC_TMR32B0->IR = 0x1<<4;            /* clear interrupt flag */
    timer32_0_capture++;
  }
  return;
}
so i added test123(); to that part and now its working
Bit ugly but hey
0 Kudos

402 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by qili on Thu Jul 28 13:24:13 MST 2011
it probably isn't that difficult to write two routines:

1) initialize the timer: this will set the timer to trip after a user-specified period of time;

2) hook in a user code to be run by the timer isr: you can use a function pointer for that.

this allows the user code to be run periodically, at a user-specified interval.
0 Kudos

402 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ferix on Thu Jul 28 13:09:15 MST 2011
Bit Angle Modulation is a software PWM, hardware PWM is working like a charm already
Its more, how can i do stuff in my main void and once every time, when a timer triggers, go out of the main void to a new void.

when i make something like this and put it all at the bottom of my code and call it in my main void it works:
Int test123 (void)
{
GPIOSetValue(0, 7, 1);
}
i want the same but then when a timer "Interrupts" that it then executes a void.
almost at the bottom of this PDF is some info about Bit Angle Modulation:
http://www.artisticlicence.com/WebSiteMaster/App%20Notes/appnote011.pdf
0 Kudos

402 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Thu Jul 28 11:58:32 MST 2011
Forum Search ? Google ?

http://www.microbuilder.eu/projects/LPC1343ReferenceDesign/LPC1343_LPC1114_PWM.aspx
0 Kudos