<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>LPCXpresso IDE中的主题 Re: Lessons Learned from Using Embedded Artists Baseboard with LPC17xx (for reference)</title>
    <link>https://community.nxp.com/t5/LPCXpresso-IDE/Lessons-Learned-from-Using-Embedded-Artists-Baseboard-with/m-p/550017#M11234</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by daniel.widyanto on Mon Oct 22 22:07:03 MST 2012&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks, filling the CCR, instead of CTCR to set the Timer mode is definitely a mistake.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I will update the developer for the issue.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 15 Jun 2016 23:27:09 GMT</pubDate>
    <dc:creator>lpcware</dc:creator>
    <dc:date>2016-06-15T23:27:09Z</dc:date>
    <item>
      <title>Lessons Learned from Using Embedded Artists Baseboard with LPC17xx (for reference)</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Lessons-Learned-from-Using-Embedded-Artists-Baseboard-with/m-p/550016#M11233</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by IntStarFoo on Mon Oct 22 10:02:27 MST 2012&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Hi All,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have been working with the EA Baseboard and the LPC1769.&amp;nbsp; I downloaded the example projects from &lt;/SPAN&gt;&lt;A href="http://" rel="nofollow noopener noreferrer" target="_blank"&gt;http://www.embeddedartists.com/support/xpr/base&lt;/A&gt;&lt;SPAN&gt; and started playing around.&amp;nbsp; I decided to make my own project using the LIB_MCU, Lib_Ea_Baseboard and CMSIS v2.&amp;nbsp; My goal was to create an output signal for sending to an external system and I needed to have a 1us timer with interrupts to do so. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So, I'm new to embedded programming and this was my first time using timers and interrupts.&amp;nbsp; I watched a few YouTube videos that were very helpful in understanding the basics.&amp;nbsp; I read through the LPC17xx user manual (UM10360) and was more confused than before.&amp;nbsp; I figured the Library code would be helpful because the naming and structure defines helped to disambiguate all of the TLAs involved and the sample code seemed elegant.&amp;nbsp;&amp;nbsp; The examples include using lpc17xx_timer.c from LIB_MCU and I followed the examples to configure my timer.&amp;nbsp; TIM_TIMERCFG_Type, TIM_MATCHCFG_Type and TIM_Init seemed to be exactly what I was looking for.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I put everything together and wrote my ~first interrupt based application.&amp;nbsp; It was simply not working as expected.&amp;nbsp; I barely knew enough to copy and paste the code and adapt it to my situation...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;// Initialize timer 0, prescale count time of 1uS
TIM_ConfigStruct.PrescaleOption = TIM_PRESCALE_USVAL;
TIM_ConfigStruct.PrescaleValue= 1;
// use channel 0, MR0
TIM_MatchConfigStruct.MatchChannel = 0;
// Enable interrupt when MR0 matches the value in TC register
TIM_MatchConfigStruct.IntOnMatch&amp;nbsp;&amp;nbsp; = TRUE;
//Enable reset on MR0: TIMER will reset if MR0 matches it
TIM_MatchConfigStruct.ResetOnMatch = FALSE;
//Stop on MR0 if MR0 matches it
TIM_MatchConfigStruct.StopOnMatch&amp;nbsp; = FALSE;
//Let me take care of MR0.0 pin if MR0 matches it
TIM_MatchConfigStruct.ExtMatchOutputType = TIM_EXTMATCH_NOTHING;
// Set Match value to 1 for 1us interuupts
TIM_MatchConfigStruct.MatchValue&amp;nbsp;&amp;nbsp; = 1;

// Set configuration for Tim_config and Tim_MatchConfig
TIM_Init(LPC_TIM0, TIM_TIMER_MODE,&amp;amp;TIM_ConfigStruct);
TIM_ConfigMatch(LPC_TIM0,&amp;amp;TIM_MatchConfigStruct);

/* preemption = 1, sub-priority = 1 */
NVIC_SetPriority(TIMER0_IRQn, ((0x01&amp;lt;&amp;lt;3)|0x01));
/* Enable interrupt for timer 0 */
NVIC_EnableIRQ(TIMER0_IRQn);&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It seemed perfect to me, yet it wasn't working.&amp;nbsp; I searched around for a week trying to figure out what the hell I was doing wrong.&amp;nbsp; After reading message boards, documentation and chatting with a veteran EE, I finally figured it out.&amp;nbsp; There is a bug in lpc17xx_timer.c!&amp;nbsp; The library was incorrectly configuring the timer.&amp;nbsp; It took me a long time to figure it out because I decided to skip over the basic understanding of what the helper functions were doing.&amp;nbsp; The lesson I learned (again) last weekend:&amp;nbsp; If you're going to use a library of helper functions, you need to have a basic understanding of what they are doing.&amp;nbsp; Learn the basics first!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So, to review... If you're going to use lpc17xx_timer.c from NXP's LIB_MCU, you should make a few fixes to the code.&amp;nbsp; The fixes are outlined by [I]'Ned Konz'[/I] &lt;/SPAN&gt;&lt;A href="http://http://forums.nxp.com/viewtopic.php?t=5696" rel="nofollow noopener noreferrer" target="_blank"&gt;here&lt;/A&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;
//THIS DOESN'T WORK IN THE CURRENT VERSION OF LIB_MCU's lpc17xx_timer.c!!!
TIM_MatchConfigStruct.ResetOnMatch = FALSE;
&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Embedded Artists Baseboard &lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://" rel="nofollow noopener noreferrer" target="_blank"&gt;http://www.embeddedartists.com/support/xpr/base&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The LPC176x sample projects...&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;lpc176x_xpr_bb_120314.zip&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks [I]'Ned Konz'[/I] for describing the fix for the bug!&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://" rel="nofollow noopener noreferrer" target="_blank"&gt;http://forums.nxp.com/viewtopic.php?t=5696&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here are the two fixed functions in lpc17xx_timer.c.&amp;nbsp; Mistakes are commented out with "LIB_MCU_BUG" and replaced just below the comment.&lt;/SPAN&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;
/*********************************************************************//**
 * @brief Initial Timer/Counter device
 *&amp;nbsp; Set Clock frequency for Timer
 * Set initial configuration for Timer
 * @param[in]TIMx&amp;nbsp; Timer selection, should be:
 * - LPC_TIM0: TIMER0 peripheral
 * - LPC_TIM1: TIMER1 peripheral
 * - LPC_TIM2: TIMER2 peripheral
 * - LPC_TIM3: TIMER3 peripheral
 * @param[in]TimerCounterMode Timer counter mode, should be:
 * - TIM_TIMER_MODE: Timer mode
 * - TIM_COUNTER_RISING_MODE: Counter rising mode
 * - TIM_COUNTER_FALLING_MODE: Counter falling mode
 * - TIM_COUNTER_ANY_MODE:Counter on both edges
 * @param[in]TIM_ConfigStruct pointer to TIM_TIMERCFG_Type
 * that contains the configuration information for the
 *&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; specified Timer peripheral.
 * @return None
 **********************************************************************/
void TIM_Init(LPC_TIM_TypeDef *TIMx, TIM_MODE_OPT TimerCounterMode, void *TIM_ConfigStruct)
{
TIM_TIMERCFG_Type *pTimeCfg;
TIM_COUNTERCFG_Type *pCounterCfg;

CHECK_PARAM(PARAM_TIMx(TIMx));
CHECK_PARAM(PARAM_TIM_MODE_OPT(TimerCounterMode));

//set power

if (TIMx== LPC_TIM0)
{
CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCTIM0, ENABLE);
//PCLK_Timer0 = CCLK/4
CLKPWR_SetPCLKDiv (CLKPWR_PCLKSEL_TIMER0, CLKPWR_PCLKSEL_CCLK_DIV_4);
}
else if (TIMx== LPC_TIM1)
{
CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCTIM1, ENABLE);
//PCLK_Timer1 = CCLK/4
CLKPWR_SetPCLKDiv (CLKPWR_PCLKSEL_TIMER1, CLKPWR_PCLKSEL_CCLK_DIV_4);
}

else if (TIMx== LPC_TIM2)
{
CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCTIM2, ENABLE);
//PCLK_Timer2= CCLK/4
CLKPWR_SetPCLKDiv (CLKPWR_PCLKSEL_TIMER2, CLKPWR_PCLKSEL_CCLK_DIV_4);
}
else if (TIMx== LPC_TIM3)
{
CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCTIM3, ENABLE);
//PCLK_Timer3= CCLK/4
CLKPWR_SetPCLKDiv (CLKPWR_PCLKSEL_TIMER3, CLKPWR_PCLKSEL_CCLK_DIV_4);
}

//LIB_MCU_BUG TIMx-&amp;gt;CCR &amp;amp;= ~TIM_CTCR_MODE_MASK;
//LIB_MCU_BUG TIMx-&amp;gt;CCR |= TIM_TIMER_MODE;

TIMx-&amp;gt;CTCR &amp;amp;= ~TIM_CTCR_MODE_MASK;
TIMx-&amp;gt;CTCR |= TimerCounterMode;

TIMx-&amp;gt;TC =0;
TIMx-&amp;gt;PC =0;
TIMx-&amp;gt;PR =0;
TIMx-&amp;gt;TCR |= (1&amp;lt;&amp;lt;1); //Reset Counter
TIMx-&amp;gt;TCR &amp;amp;= ~(1&amp;lt;&amp;lt;1); //release reset

if (TimerCounterMode == TIM_TIMER_MODE )
{
pTimeCfg = (TIM_TIMERCFG_Type *)TIM_ConfigStruct;
if (pTimeCfg-&amp;gt;PrescaleOption&amp;nbsp; == TIM_PRESCALE_TICKVAL)
{
TIMx-&amp;gt;PR&amp;nbsp;&amp;nbsp; = pTimeCfg-&amp;gt;PrescaleValue -1&amp;nbsp; ;
}
else
{
TIMx-&amp;gt;PR&amp;nbsp;&amp;nbsp; = converUSecToVal (converPtrToTimeNum(TIMx),pTimeCfg-&amp;gt;PrescaleValue)-1;
}
}
else
{

pCounterCfg = (TIM_COUNTERCFG_Type *)TIM_ConfigStruct;
//LIB_MCU_BUG TIMx-&amp;gt;CCR&amp;nbsp; &amp;amp;= ~TIM_CTCR_INPUT_MASK;
TIMx-&amp;gt;CTCR &amp;amp;= ~TIM_CTCR_INPUT_MASK;
if (pCounterCfg-&amp;gt;CountInputSelect == TIM_COUNTER_INCAP1)
{
//LIB_MCU_BUG TIMx-&amp;gt;CCR |= _BIT(2);
TIMx-&amp;gt;CTCR |= _BIT(2);
}
}

// Clear interrupt pending
TIMx-&amp;gt;IR = 0xFFFFFFFF;

}&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;
/*********************************************************************//**
 * @brief Convert a timer register pointer to a timer number
 * @param[in]TIMx Pointer to LPC_TIM_TypeDef, should be:
 * - LPC_TIM0: TIMER0 peripheral
 * - LPC_TIM1: TIMER1 peripheral
 * - LPC_TIM2: TIMER2 peripheral
 * - LPC_TIM3: TIMER3 peripheral
 * @return The timer number (0 to 3) or -1 if register pointer is bad
 **********************************************************************/
uint32_t converPtrToTimeNum (LPC_TIM_TypeDef *TIMx)
{
//LIB_MCU_BUG uint32_t tnum = -1;
uint32_t tnum = (uint32_t)-1;

if (TIMx == LPC_TIM0)
{
tnum = 0;
}
else if (TIMx == LPC_TIM1)
{
tnum = 1;
}
else if (TIMx == LPC_TIM2)
{
tnum = 2;
}
else if (TIMx == LPC_TIM3)
{
tnum = 3;
}

return tnum;
}&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 23:27:08 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Lessons-Learned-from-Using-Embedded-Artists-Baseboard-with/m-p/550016#M11233</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T23:27:08Z</dc:date>
    </item>
    <item>
      <title>Re: Lessons Learned from Using Embedded Artists Baseboard with LPC17xx (for reference)</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Lessons-Learned-from-Using-Embedded-Artists-Baseboard-with/m-p/550017#M11234</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by daniel.widyanto on Mon Oct 22 22:07:03 MST 2012&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks, filling the CCR, instead of CTCR to set the Timer mode is definitely a mistake.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I will update the developer for the issue.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 23:27:09 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Lessons-Learned-from-Using-Embedded-Artists-Baseboard-with/m-p/550017#M11234</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T23:27:09Z</dc:date>
    </item>
    <item>
      <title>Re: Lessons Learned from Using Embedded Artists Baseboard with LPC17xx (for reference)</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Lessons-Learned-from-Using-Embedded-Artists-Baseboard-with/m-p/550018#M11235</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by frame on Mon Oct 22 22:50:12 MST 2012&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Apart from the timer bug in the library, a 1us interrupt is a rather heavy load for the uC.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;These are about 120 instructions (at max. speed), for servicing the interrupt AND doing anything else.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;It might work if there is no other performance load, but don't be surprised if the code misbehaves&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;when adding modest functionality.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 23:27:09 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Lessons-Learned-from-Using-Embedded-Artists-Baseboard-with/m-p/550018#M11235</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T23:27:09Z</dc:date>
    </item>
  </channel>
</rss>

