<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.arm.com/utility/feedstylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>TImer_Interrupts</title><link>https://community.arm.com/developer/tools-software/tools/f/keil-forum/33673/timer_interrupts</link><description> 
Hi Folks, 

 
I am trying to work on Timer Interrupts. I want to start an LED
when a TIMER match occurs. I have called an Interrupt on match and
the LED should glow when the match occurs. I am not able to perceive
the output. I am not exactly getting</description><dc:language>en-US</dc:language><generator>Telligent Community 10</generator><item><title>RE: TImer_Interrupts</title><link>https://community.arm.com/thread/143660?ContentTypeID=1</link><pubDate>Wed, 27 Jan 2016 01:08:48 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:3f400bfb-676e-4169-841e-f42071d005dd</guid><dc:creator>edPer Westermark</dc:creator><description>&lt;p&gt;&lt;p&gt;
So - what frequency do you get? The difference between expected
and actual frequency is normally a good hint at what is incorrectly
configured - debugging is all about picking up the available clues
and evaluate them.&lt;/p&gt;

&lt;p&gt;
If you have 12 MHz, then you somehow have to divide that down to 1
Hz for your expected interrupt frequency. I haven&amp;#39;t seen you try any
values that would be even close to such attempt - on the first code
post you ignored the match control register despite requesting an
interrupt on match. In the second post, you made a bit of a random
assignment for the match control register - and arbitrary values
tends to give arbitrary results.&lt;/p&gt;

&lt;p&gt;
Wouldn&amp;#39;t it be an idea to fix the things that have already been
mentioned?&lt;/p&gt;

&lt;p&gt;
Like making some reasonable attempt at setting a value for the
match control register?&lt;/p&gt;

&lt;p&gt;
Or making sure the program doesn&amp;#39;t exit main() before the
processor have time to produce the first interrupt?&lt;/p&gt;

&lt;p&gt;
The processor will not ignore details, even if you do.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TImer_Interrupts</title><link>https://community.arm.com/thread/140944?ContentTypeID=1</link><pubDate>Tue, 26 Jan 2016 20:10:36 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:783d706d-463d-4d3c-a0b0-2bdd77835894</guid><dc:creator>Aniruddha Vyawahare</dc:creator><description>&lt;p&gt;&lt;p&gt;
I am using VPBCLK = CPU Clock (12Mhz) and expecting a 1 Sec delay.
Means an ISR should be called after this delay.Can you please tell,
how to configure the interrupt frequency?&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TImer_Interrupts</title><link>https://community.arm.com/thread/140928?ContentTypeID=1</link><pubDate>Thu, 21 Jan 2016 06:38:13 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:4f93ec89-5e58-44ca-8e70-1d23fa832e0f</guid><dc:creator>Kevin Pollark</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;Are you aware that there is no need to write a 32-bit
hexadecimal number using 8 digits.&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
&lt;i&gt;0x00000000 is the same value as 0x00 or 0. The first form is
just taking longer time for you to write.&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
True, but it is certainly a habit I&amp;#39;m guilty of exhibiting (though
guilty may not really be the right word).&lt;/p&gt;

&lt;p&gt;
The reason I do it is simple: it emphasizes the size of those
numerous SFRs etc when glancing back at the code.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TImer_Interrupts</title><link>https://community.arm.com/thread/137305?ContentTypeID=1</link><pubDate>Thu, 21 Jan 2016 05:01:40 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:1099843c-929d-4a2c-9d91-b1df1664924e</guid><dc:creator>edPer Westermark</dc:creator><description>&lt;p&gt;&lt;p&gt;
Your program is still running out of main() instantly. So - do you
expect there to be a cozy command line or GUI to pick up the
processor after your program decides to quickly end? This was point 8
in my previous post.&lt;/p&gt;

&lt;p&gt;
And you have configured the timer at an extremely high interrupt
frequency - it isn&amp;#39;t meaningful to try to configure for a frequency
higher than what the processor is fast enough to be able to service.
Why don&amp;#39;t you tell us what timer frequency you plan for - and why you
think you need to run timer interrupts at such a wild frequency.
Remember that all CPU time spent in an interrupt handler is CPU time
lost from the main loop (assuming that your program actually had a
main loop...) I covered short delay times in a different thread.
Think about how many clock cycles it may take to handle one timer
interrupt. Think about how many clock cycles there will be between
two interrupts. That gives you an idea how much time you leave for
the CPU to do other stuff.&lt;/p&gt;

&lt;p&gt;
&amp;quot;//Enabling the vector&amp;quot;&lt;br /&gt;
Enabling what vector? Why not write that it&amp;#39;s specifically the timer
0 interrupt you are enabling?&lt;/p&gt;

&lt;p&gt;
And you shouldn&amp;#39;t enable the timer until _after_ you have
registered the interrupt handler. Normal code is the clear the
counter value and enable the timer as the last two steps - when
everything else has already been prepared and ready. If you enable it
early, and have a very short timer period, then it could have time to
perform the match before you had the time to actually enable the
interrupt in the VIC.&lt;/p&gt;

&lt;p&gt;
Are you aware that there is no need to write a 32-bit hexadecimal
number using 8 digits.&lt;/p&gt;

&lt;p&gt;
0x00000000 is the same value as 0x00 or 0. The first form is just
taking longer time for you to write.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TImer_Interrupts</title><link>https://community.arm.com/thread/129149?ContentTypeID=1</link><pubDate>Wed, 20 Jan 2016 21:20:22 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:5958cc11-427f-4980-a5b4-e775c2f5a7db</guid><dc:creator>Aniruddha Vyawahare</dc:creator><description>&lt;p&gt;&lt;p&gt;
I have updated the code as shown below. I debugged the code and
noticed, that the VICVectAddr0 is updated with an address where its
handler (&lt;b&gt;void Timer0_IRQ(void)__irq&lt;/b&gt;) is located. Still the
compiler is not jumping into the IRQ.&lt;/p&gt;

&lt;p&gt;
Need help!!&lt;/p&gt;

&lt;pre&gt;
#include &amp;lt;LPC21xx.H&amp;gt;

void Timer0_IRQ(void)__irq;

int main()
{

        IO0DIR = 0X0000000A;

        T0TCR = 0X00000000;          //Disable Timer

        T0MCR = 0X00000003;          //Reset and generate an interrupt on Match

        T0PC = 0X00000000;

        T0PR = 0X00000000;           //T0TC should increment on PR+1 clk



        T0MR0 = 0XFF;                //Value in Match Register

        T0TC = 0X00;                 //Reset Value in Timer Counter

        T0TCR = 0X00000001;          // Enable Timer



        VICVectAddr0 = (unsigned)Timer0_IRQ;

        VICVectCntl0 = 0X00000024;       //Assigning Timer0 Interrupt to an IRQ Slot

        VICIntEnable = 0X00000010;       //Enabling the vector


        IO0SET = 0X00000002;
}


void Timer0_IRQ(void)__irq

{

        IO0CLR = 0X00000002;

        IO0SET = 0X00000008;

        T0IR = 0X01;                     //Clear Timer Match0 interrupt flag

        VICVectAddr = 0X00000000;        // End of Interrupt execution

}
&lt;/pre&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TImer_Interrupts</title><link>https://community.arm.com/thread/117949?ContentTypeID=1</link><pubDate>Wed, 20 Jan 2016 19:54:24 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:bf263f60-2cd9-4e1e-a496-94b31a4419df</guid><dc:creator>Aniruddha Vyawahare</dc:creator><description>&lt;p&gt;&lt;p&gt;
Hi Per,&lt;/p&gt;

&lt;p&gt;
Thanks for your valuable feedback. I&amp;#39;ll take your comments
positively as I am a beginner in Embedded C programming and also in
ARM, so comments like these are always welcome!&lt;/p&gt;

&lt;p&gt;
In reply to your mentioned points,&lt;/p&gt;

&lt;p&gt;
1.I saw the posting instructions about source code.&lt;br /&gt;
2.I am using NXP&amp;#39;s - LPC2129&lt;/p&gt;

&lt;p&gt;
4.I incorporated this change.&lt;br /&gt;
5.I wanted to tick the Timer Counter on every PR+1 clock, hence I
used T0PR = 0X00000000&lt;br /&gt;
6.Yes, I want an Interrupt when match occurs. Hence I have mentioned
this &amp;quot;T0MCR = 0X00000003; //Reset and generate an interrupt on Match&amp;quot;
in the code. I have specified the Match value in the IRQ as &amp;quot;T0MR0 =
0XFF&amp;quot;&lt;br /&gt;
7.Got your point.&lt;/p&gt;

&lt;p&gt;
10.#define MR0I_Flag 0X01 //I am AND&amp;#39;ing the value which I
specified in the Match Control register with T0IR register and now
comparing it with 0X01&lt;/p&gt;

&lt;p&gt;
Why the compiler is not entering into the IRQ?&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TImer_Interrupts</title><link>https://community.arm.com/thread/108640?ContentTypeID=1</link><pubDate>Tue, 19 Jan 2016 12:41:49 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:8f3c77ad-cacf-4913-8ba6-293c4138be47</guid><dc:creator>edPer Westermark</dc:creator><description>&lt;p&gt;&lt;p&gt;
1) You didn&amp;#39;t seem to notice the posting instructions for how to
post source code.&lt;/p&gt;

&lt;p&gt;
2) You didn&amp;#39;t thought about mentioning which processor you are
using - you leave it to people to look at the #include you are
using.&lt;/p&gt;

&lt;p&gt;
3) There are a large number of threads on this forum about how to
use LPC21xx timers with interrupts - I don&amp;#39;t think you have spent
much time looking.&lt;/p&gt;

&lt;p&gt;
4) You like to enable your interrupts _before_ you set an
interrupt handler - any reason why you think that is a good idea?&lt;/p&gt;

&lt;p&gt;
5) You are using a very &amp;quot;interesting&amp;quot; prescaler value - exactly
what is your plan?&lt;/p&gt;

&lt;p&gt;
6) You want an interrupt on &amp;quot;Match&amp;quot;. Which match? What matching
value have you specified?&lt;/p&gt;

&lt;p&gt;
7) You use a temporary variable &amp;quot;regval&amp;quot; to read out the value of
T0IR in your interrupt handler - but then you immediately make use of
T0IR again to check if you got a match. Shouldn&amp;#39;t the interrupt flags
you clear correspond with the interrupt flags you have processed?&lt;/p&gt;

&lt;p&gt;
8) You write a main() that just sets up a number of registers and
then directly exits - what do you expect the processor to do after
you leave main()?&lt;/p&gt;

&lt;p&gt;
9) Most compilers would even warn if you have a function returning
type &amp;quot;int&amp;quot; and you leave the function without a return &amp;lt;val&amp;gt;
statement - so are you making use of the warning functionality of the
compiler?&lt;/p&gt;

&lt;p&gt;
10) You have one #define named &amp;quot;MR0I_FLAG&amp;quot;. But what does that
name actually say? That you have an interrupt? But when reading out
the T0IR register you already know you have a timer 0 interrupt -
shouldn&amp;#39;t the #define at least mention either the meaning of the
interrupt, or the timer condition that caused that specific
interrupt? Named constants are only meaningful if their name actually
tells the reader something meaningful - shouldn&amp;#39;t the message be that
you got a MR0 interrupt? Because it was match register 0 you enabled
match interrupts for.&lt;/p&gt;

&lt;p&gt;
11) You peppered the code with lots of magic values - how would a
reader know what this line actually means?&lt;/p&gt;

&lt;pre&gt;
VICIntEnable = 0X00000010;
&lt;/pre&gt;

&lt;p&gt;
&lt;br /&gt;
The term &amp;quot;magic value&amp;quot; is really quite appropriate - the above line
looks mostly like a magic incantation. Without access to the
processor manual, it&amp;#39;s hard to know that the line enables interrupts
for timer 0 - and at the same time disables interrupts for all other
interrupt sources!&lt;/p&gt;

&lt;p&gt;
Would you be able to tell your teacher, line-by-line, what the
individual lines in your code does - and exactly why you need them
and why you have placed them in that specific order?&lt;/p&gt;

&lt;pre&gt;
#include&amp;lt;lpc21xx.h&amp;gt;

#define MR0I_FLAG 0X01

void led(void)__irq {
    long int regval;
    regval = T0IR;

    if(T0IR &amp;amp; MR0I_FLAG) {
        T0MR0 = 0XFF;
        T0TC = 0X00;
        T0TCR = 0X00000001;

        IO0CLR = 0X00000002;
        IO0SET = 0X00000008;
    }

    T0IR = regval;
    VICVectAddr0 = 0X00000000;
}

int main() {
    IO0DIR = 0X0000000A;
    T0TCR = 0X00000000;
    T0MCR = 0X00000003; //Reset and generate an interrupt on Match
    T0PC = 0X00000000;
    T0PR = 0X00000000;

    VICIntEnable = 0X00000010;
    VICVectCntl0 = 0X00000024;
    VICVectAddr0 = (unsigned)led;

    IO0SET = 0X00000002;
}
&lt;/pre&gt;

&lt;p&gt;
So in short - are you sure you have really done enough homework to
give a reason to start this thread? Your teacher really expects _you_
to do a bit of work too...&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TImer_Interrupts</title><link>https://community.arm.com/thread/83009?ContentTypeID=1</link><pubDate>Tue, 19 Jan 2016 12:07:51 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:a82220a8-ae14-4b7c-a8db-969ef95c9121</guid><dc:creator>Aniruddha Vyawahare</dc:creator><description>&lt;p&gt;&lt;p&gt;
Hi Westonsupermare Pier,&lt;/p&gt;

&lt;p&gt;
Yes, as you said, its not going into IRQ. Can u please tell me
what could be the reason?&lt;/p&gt;

&lt;p&gt;
Thanks.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TImer_Interrupts</title><link>https://community.arm.com/thread/64437?ContentTypeID=1</link><pubDate>Tue, 19 Jan 2016 12:00:37 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:615da46d-613e-4b36-9099-a9ee15c5de75</guid><dc:creator>Westonsupermare Pier</dc:creator><description>&lt;p&gt;&lt;p&gt;
Make sure it doesn&amp;#39;t drop out the bottom of main(), perhaps use a
debugger to confirm if it enters the IRQ, and what the peripheral
registers are doing.&lt;/p&gt;

&lt;p&gt;
Please also review posting instructions related to source
code.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>