<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/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/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Not able to setup timer interrupt in nRF51822</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/11100/not-able-to-setup-timer-interrupt-in-nrf51822</link><description>Timer_interrupt.txt 
 Hi all, can anyone please help me in setup up the timer interrupt? I could only see the printing of &amp;quot;Entered 2&amp;quot;. Kindly check on the attached text file for my code. Kindly assist. Thanks in advance.</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 06 Feb 2017 08:55:23 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/11100/not-able-to-setup-timer-interrupt-in-nrf51822" /><item><title>RE: Not able to setup timer interrupt in nRF51822</title><link>https://devzone.nordicsemi.com/thread/41571?ContentTypeID=1</link><pubDate>Mon, 06 Feb 2017 08:55:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3761541d-f7dc-42d7-bcc5-0162567b7d1d</guid><dc:creator>NK99</dc:creator><description>&lt;p&gt;I followed your instructions on issue and i had very nice results. I am trying to control a dc motor with a very fast encoder with redbear ble nano and i was wondering if you have any suggestions. I used your code for the pid command but im still having trouble reading the encoder and i was wondering if i can have more time interrupts? Maybe something with the qdec peripheral? Need help!!!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Not able to setup timer interrupt in nRF51822</title><link>https://devzone.nordicsemi.com/thread/41570?ContentTypeID=1</link><pubDate>Tue, 05 Jan 2016 08:23:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:da4f9a6b-ba0f-4899-b0d1-2e159d0ad5e0</guid><dc:creator>adrianwong</dc:creator><description>&lt;p&gt;Thank you so much Monpetit!!! I solved it.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Not able to setup timer interrupt in nRF51822</title><link>https://devzone.nordicsemi.com/thread/41569?ContentTypeID=1</link><pubDate>Tue, 05 Jan 2016 07:56:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:10ad1171-bf1d-44a1-a0e6-cf8d3f978e69</guid><dc:creator>adrianwong</dc:creator><description>&lt;p&gt;Now it is working and displaying &amp;quot;Entered 1&amp;quot;. I realized that add this line &amp;quot;if ((tCount % 300) == 0)&amp;quot; make the difference. What is the reason?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Not able to setup timer interrupt in nRF51822</title><link>https://devzone.nordicsemi.com/thread/41568?ContentTypeID=1</link><pubDate>Tue, 05 Jan 2016 07:51:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f6cf4ed6-d0fa-4ea5-a82a-62317efab88b</guid><dc:creator>adrianwong</dc:creator><description>&lt;p&gt;okay. I try changing comp1 to have the timer interval of 1s. but is not working.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Not able to setup timer interrupt in nRF51822</title><link>https://devzone.nordicsemi.com/thread/41567?ContentTypeID=1</link><pubDate>Tue, 05 Jan 2016 07:44:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:454e11c2-1491-4fb5-b132-02c35f397a26</guid><dc:creator>monpetit</dc:creator><description>&lt;p&gt;adrianwong, your code differs from my code. And please copy and paste my code exactly. My code separates function prototype and body.&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve just modified my code corresponding to your new code with Arduino 1.6.7 and BLE Nano v1.5(32KB). I don&amp;#39;t know how long timer interval do you want. But my code print out &amp;#39;Entered 1&amp;#39;.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Not able to setup timer interrupt in nRF51822</title><link>https://devzone.nordicsemi.com/thread/41566?ContentTypeID=1</link><pubDate>Tue, 05 Jan 2016 07:21:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c446fdf1-140b-4b87-af61-7c86b41014c6</guid><dc:creator>adrianwong</dc:creator><description>&lt;p&gt;Now i realized that after going into the &amp;quot;start_timer()&amp;quot; function it couldn&amp;#39;t come out. As i put a printout after start_timer() inside the setup(), nothing is printed out. Any idea?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Not able to setup timer interrupt in nRF51822</title><link>https://devzone.nordicsemi.com/thread/41557?ContentTypeID=1</link><pubDate>Tue, 05 Jan 2016 06:39:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4744bf16-d5ef-484a-b96c-e476b1b7e8e7</guid><dc:creator>adrianwong</dc:creator><description>&lt;p&gt;Thank. Now i able to get into interrupt function but now having another problems&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Not able to setup timer interrupt in nRF51822</title><link>https://devzone.nordicsemi.com/thread/41565?ContentTypeID=1</link><pubDate>Tue, 05 Jan 2016 06:25:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8f2050c3-af78-453b-ba8e-dfef5cc037f6</guid><dc:creator>adrianwong</dc:creator><description>&lt;p&gt;Hi, I already posted a new code. please check out the &amp;quot;Timer_Interrupt.txt&amp;quot;. I able to make it displaying &amp;quot;Entered 3&amp;quot; but in a very rapid speed even though after manipulating the value of &amp;quot;comp1&amp;quot;. Besides that, I cannot see any display of &amp;quot;Entered 1&amp;quot; so i assume the loop() is not working.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Not able to setup timer interrupt in nRF51822</title><link>https://devzone.nordicsemi.com/thread/41556?ContentTypeID=1</link><pubDate>Tue, 05 Jan 2016 06:23:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9c42a130-0d4a-40cc-8015-9d6ded4f9807</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;Monpetit answered your question - it&amp;#39;s C++ vs C linkage and it would have helped if you&amp;#39;d pointed out you were using Arduino build environment at the start. You need to figure out how to fix the compilation error you&amp;#39;re getting - which means starting by working out where the previous definition comes from which is using C++ linkage.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Not able to setup timer interrupt in nRF51822</title><link>https://devzone.nordicsemi.com/thread/41564?ContentTypeID=1</link><pubDate>Tue, 05 Jan 2016 06:01:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fa813ecc-9035-459b-a537-70100ea5d014</guid><dc:creator>adrianwong</dc:creator><description>&lt;p&gt;Yes I did.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Not able to setup timer interrupt in nRF51822</title><link>https://devzone.nordicsemi.com/thread/41563?ContentTypeID=1</link><pubDate>Tue, 05 Jan 2016 05:36:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:efd9046a-bbe5-448c-844f-28bab59ab75d</guid><dc:creator>monpetit</dc:creator><description>&lt;p&gt;Did you copy and paste my code?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Not able to setup timer interrupt in nRF51822</title><link>https://devzone.nordicsemi.com/thread/41562?ContentTypeID=1</link><pubDate>Tue, 05 Jan 2016 05:32:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a4560a95-5ac7-4bf2-bbe5-d8e923338243</guid><dc:creator>adrianwong</dc:creator><description>&lt;p&gt;I couldn&amp;#39;t compile. These are the errors : error: conflicts with new declaration with &amp;#39;C&amp;#39; linkage
previous declaration of &amp;#39;void TIMER1_IRQHandler()&amp;#39; with &amp;#39;C++&amp;#39; linkage&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Not able to setup timer interrupt in nRF51822</title><link>https://devzone.nordicsemi.com/thread/41561?ContentTypeID=1</link><pubDate>Tue, 05 Jan 2016 04:36:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:afec46dd-f9f1-43c5-a973-1e9537d02bb7</guid><dc:creator>adrianwong</dc:creator><description>&lt;p&gt;Ok. I will give it a try and let you know soon.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Not able to setup timer interrupt in nRF51822</title><link>https://devzone.nordicsemi.com/thread/41577?ContentTypeID=1</link><pubDate>Tue, 05 Jan 2016 04:35:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d2463ce7-9023-4b1d-9e99-e9091e74910e</guid><dc:creator>adrianwong</dc:creator><description>&lt;p&gt;I already try flashing of LED. But still getting the same result.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Not able to setup timer interrupt in nRF51822</title><link>https://devzone.nordicsemi.com/thread/41573?ContentTypeID=1</link><pubDate>Tue, 05 Jan 2016 04:35:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:87f19bb6-3394-4bc8-928b-a8dd1721bc35</guid><dc:creator>adrianwong</dc:creator><description>&lt;p&gt;Ya. In Arduino IDE. I&amp;#39;m using a library that can compile nordic code in Arduino IDE&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Not able to setup timer interrupt in nRF51822</title><link>https://devzone.nordicsemi.com/thread/41560?ContentTypeID=1</link><pubDate>Tue, 05 Jan 2016 01:48:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:13001a3a-9100-4dde-8f62-40ffc2e6606a</guid><dc:creator>monpetit</dc:creator><description>&lt;p&gt;Arduino source code is compiled as C++, but IRQ Handler is linked as C. So you have to declare &lt;code&gt;void TIMER1_IRQHandler(void)&lt;/code&gt; with C linkage.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;nrf.h&amp;gt;

#ifdef __cplusplus
extern &amp;quot;C&amp;quot; {
#endif
void TIMER1_IRQHandler(void);
#ifdef __cplusplus
}
#endif

// count to us (micro seconds) conversion factor
// set in start_timer()
static volatile float countToUs = 1;

// counter
static volatile uint32_t tCount = 0;


// set up and start Timer1
void start_timer(void)
{
    NRF_TIMER1-&amp;gt;MODE = TIMER_MODE_MODE_Timer;
    NRF_TIMER1-&amp;gt;TASKS_CLEAR = 1;
    // set prescalar n
    // f = 16 MHz / 2^(n)
    uint8_t prescaler = 0;
    NRF_TIMER1-&amp;gt;PRESCALER = prescaler;
    NRF_TIMER1-&amp;gt;BITMODE = TIMER_BITMODE_BITMODE_16Bit;

    // 16 MHz clock generates timer tick every 1/(16000000) s = 62.5 nano s
    // With compare enabled, the interrupt is fired every: 62.5 * comp1 nano s
    // = 0.0625*comp1 micro seconds
    // multiply this by 2^(prescalar)

    uint16_t comp1 = 500;
    // set compare
    NRF_TIMER1-&amp;gt;CC[1] = comp1;

    // set conversion factor
    countToUs = 0.0625 * comp1 * (1 &amp;lt;&amp;lt; prescaler);

    //printf(&amp;quot;timer tick = %f us\n&amp;quot;, countToUs);

    // enable compare 1
    NRF_TIMER1-&amp;gt;INTENSET =
        (TIMER_INTENSET_COMPARE1_Enabled &amp;lt;&amp;lt; TIMER_INTENSET_COMPARE1_Pos);

    // use the shorts register to clear compare 1
    NRF_TIMER1-&amp;gt;SHORTS = (TIMER_SHORTS_COMPARE1_CLEAR_Enabled &amp;lt;&amp;lt;
                          TIMER_SHORTS_COMPARE1_CLEAR_Pos);

    // enable IRQ
    NVIC_EnableIRQ(TIMER1_IRQn);

    Serial.println(&amp;quot;Entered 2&amp;quot;);

    // start timer
    NRF_TIMER1-&amp;gt;TASKS_START = 1;

}

// Timer 1 IRQ handler
// just increment count
void TIMER1_IRQHandler(void)
{
    Serial.println(&amp;quot;Entered 3&amp;quot;);

    if (NRF_TIMER1-&amp;gt;EVENTS_COMPARE[1] &amp;amp;&amp;amp;
            NRF_TIMER1-&amp;gt;INTENSET &amp;amp; TIMER_INTENSET_COMPARE1_Msk) {

        // clear compare register event
        NRF_TIMER1-&amp;gt;EVENTS_COMPARE[1] = 0;

        // increment count
        tCount++;
    }
}

void setup()
{
    // put your setup code here, to run once:
    Serial.begin(9600);

    delay(2000);

    start_timer();
}

void loop()
{
    // put your main code here, to run repeatedly:
    Serial.println(&amp;quot;Entered 1&amp;quot;);
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Good Luck! :)&lt;/p&gt;
&lt;p&gt;New code:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;nrf.h&amp;gt;

// count to us (micro seconds) conversion factor
// set in start_timer()
static volatile float countToUs = 1;

// counter
static volatile uint32_t tCount = 0;


#ifdef __cplusplus
extern &amp;quot;C&amp;quot; {
#endif
void TIMER1_IRQHandler(void);
#ifdef __cplusplus
}
#endif


// Timer 1 IRQ handler
// just increment count
void TIMER1_IRQHandler(void)
{
    if (NRF_TIMER1-&amp;gt;EVENTS_COMPARE[1] &amp;amp;&amp;amp;
            NRF_TIMER1-&amp;gt;INTENSET &amp;amp; TIMER_INTENSET_COMPARE1_Msk) {

        // clear compare register event
        NRF_TIMER1-&amp;gt;EVENTS_COMPARE[1] = 0;

        // increment count
        tCount++;

        if ((tCount % 300) == 0)
            Serial.println(&amp;quot;Entered 3&amp;quot;);
    }
}


// set up and start Timer1
void start_timer(void)
{
    NRF_TIMER1-&amp;gt;MODE = TIMER_MODE_MODE_Timer;
    NRF_TIMER1-&amp;gt;TASKS_CLEAR = 1;
    // set prescalar n
    // f = 16 MHz / 2^(n)
    uint8_t prescaler = 0;
    NRF_TIMER1-&amp;gt;PRESCALER = prescaler;
    NRF_TIMER1-&amp;gt;BITMODE = TIMER_BITMODE_BITMODE_16Bit;

    // 16 MHz clock generates timer tick every 1/(16000000) s = 62.5 nano s
    // With compare enabled, the interrupt is fired every: 62.5 * comp1 nano s
    // = 0.0625*comp1 micro seconds
    // multiply this by 2^(prescalar)

    uint16_t comp1 = 500;
    // set compare
    NRF_TIMER1-&amp;gt;CC[1] = comp1;

    // set conversion factor
    countToUs = 0.0625 * comp1 * (1 &amp;lt;&amp;lt; prescaler);

    //printf(&amp;quot;timer tick = %f us\n&amp;quot;, countToUs);

    // enable compare 1
    NRF_TIMER1-&amp;gt;INTENSET =
        (TIMER_INTENSET_COMPARE1_Enabled &amp;lt;&amp;lt; TIMER_INTENSET_COMPARE1_Pos);

    // use the shorts register to clear compare 1
    NRF_TIMER1-&amp;gt;SHORTS = (TIMER_SHORTS_COMPARE1_CLEAR_Enabled &amp;lt;&amp;lt;
                          TIMER_SHORTS_COMPARE1_CLEAR_Pos);

    // enable IRQ
    NVIC_EnableIRQ(TIMER1_IRQn);

    Serial.println(&amp;quot;Entered 2&amp;quot;);

    // start timer
    NRF_TIMER1-&amp;gt;TASKS_START = 1;

}

void setup()
{
    // put your setup code here, to run once:
    Serial.begin(9600);

    delay(2000);

    start_timer();
}

void loop()
{
    // put your main code here, to run repeatedly:
    Serial.println(&amp;quot;Entered 1&amp;quot;);
    __WFE();
}
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Not able to setup timer interrupt in nRF51822</title><link>https://devzone.nordicsemi.com/thread/41572?ContentTypeID=1</link><pubDate>Mon, 04 Jan 2016 16:35:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2ec93cae-5cf0-401c-a8f5-9974049808dc</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;That code looks very Arduino, with the setup and loop() stuff. What board are you using, what development environment?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Not able to setup timer interrupt in nRF51822</title><link>https://devzone.nordicsemi.com/thread/41576?ContentTypeID=1</link><pubDate>Mon, 04 Jan 2016 15:09:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b884315e-0278-4e4d-bad3-6fdfbb8508cc</guid><dc:creator>Stefan Birnir Sverrisson</dc:creator><description>&lt;p&gt;Hmm, cant quickly see anything wrong with your code either. You could try to lower the interrupt frequency to see if that helps. You could also try to flash a LED instead of writing to serial, to see if that makes a difference.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Not able to setup timer interrupt in nRF51822</title><link>https://devzone.nordicsemi.com/thread/41559?ContentTypeID=1</link><pubDate>Mon, 04 Jan 2016 07:03:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:796c9d55-e45c-4f13-b4cb-e0e85a387862</guid><dc:creator>adrianwong</dc:creator><description>&lt;p&gt;Hi, I already tried to follow the example setup and i still stuck at the initialisation &amp;quot;start_timer()&amp;quot; as i only can see &amp;quot;Entered 2&amp;quot; is printed out. I think my code in timer_interrupt.txt had configured the timer accordingly. Kindly assist. Thanks.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Not able to setup timer interrupt in nRF51822</title><link>https://devzone.nordicsemi.com/thread/41575?ContentTypeID=1</link><pubDate>Mon, 04 Jan 2016 06:35:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b2afff91-aac8-4dae-bc36-f1fa7027a3b0</guid><dc:creator>adrianwong</dc:creator><description>&lt;p&gt;yes. This is the only code. I want to make sure the timer interrupt is working first before adding in anything to it. But so far it is still not working. I stuck at the initialisation &amp;quot;start_timer()&amp;quot; as i only can see &amp;quot;Entered 2&amp;quot; is printed out. If I comment out &amp;quot;start_timer()&amp;quot; function then i can see the print out of &amp;quot;Entered 1&amp;quot; only. Kindly assist. Thanks.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Not able to setup timer interrupt in nRF51822</title><link>https://devzone.nordicsemi.com/thread/41558?ContentTypeID=1</link><pubDate>Sat, 02 Jan 2016 03:19:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f603e504-35c0-4f91-a779-4be84f3a098d</guid><dc:creator>Michael Dietz</dc:creator><description>&lt;p&gt;A timer is configured and interrupt handler is set in this example:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/andenore/NordicSnippets/blob/master/examples/timer/main.c"&gt;github.com/.../main.c&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;also for other peripherals&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Not able to setup timer interrupt in nRF51822</title><link>https://devzone.nordicsemi.com/thread/41574?ContentTypeID=1</link><pubDate>Thu, 31 Dec 2015 21:39:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cbd12fe3-8e1a-4b44-9aa0-d55df778eb4b</guid><dc:creator>Martijn</dc:creator><description>&lt;p&gt;When I look at this code I can&amp;#39;t find any errors. Is there more code running, or is this the only code?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>