LPC54102, LPCOPen, LCPXpresso demo code Simple timer

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

LPC54102, LPCOPen, LCPXpresso demo code Simple timer

ソリューションへジャンプ
2,550件の閲覧回数
chrisoneill
Contributor I

Using OM13077 eval board,  I want to output a square wave using Timer0 match register 0, toggle pin on match.

Anything missing here?

       int loop = 1; /* Prevents unreachable statement warning */

       uint32_t timerBaseClock;

 

       SystemCoreClockUpdate();

       Board_Init();

 

       /* Initialize Timer 0 */

       Chip_TIMER_Init(LPC_TIMER0);

 

       /* Setup prescale value on Timer 0 to PCLK */

       Chip_TIMER_PrescaleSet(LPC_TIMER0, 0);

 

       /* Reset timer */

       Chip_TIMER_Reset(LPC_TIMER0);

 

       /* Get rate of timer base clock */

       timerBaseClock = Chip_Clock_GetAsyncSyscon_ClockRate();

 

       /* Setup Timer 0 for a match every 1s */

       Chip_TIMER_SetMatch(LPC_TIMER0, 0, (timerBaseClock / TICKRATE_HZ1));

 

       /* Setup timer to restart when match occurs */

       Chip_TIMER_ResetOnMatchEnable(LPC_TIMER0, 0);

 

       /* Map P1.16 as MAT0 pin */

       Chip_IOCON_PinMuxSet(LPC_IOCON, 1, 16, (IOCON_FUNC3 | IOCON_DIGITAL_EN | IOCON_INPFILT_OFF));

 

       /* Sets external match control (MATn.matchnum) pin control */

       Chip_TIMER_ExtMatchControlSet(LPC_TIMER0, 0, TIMER_EXTMATCH_TOGGLE, 0);

 

       /* Start timer */

       Chip_TIMER_Enable(LPC_TIMER0);

 

       while (loop) {

       }

 

       return 0;

ラベル(1)
0 件の賞賛
返信
1 解決策
2,142件の閲覧回数
jeremyzhou
NXP Employee
NXP Employee

Hi Chris ONeill.

The PIO1_16 is assigned to the CT32B0_MAT0 when set up the IOCON_FUN2 option (Fig 1).

2017-03-10_13-55-49.jpg

                                                                      Fig 1

Please use the amended code below which can work well (Fig 2)

新建文件2.bmp

                             Fig 2

#define TICKRATE_HZ1 (4)/* 4 ticks per second */

/* main application function (C entry point) */
int main(void)
{
     int loop = 1;     /* Prevents unreachable statement warning */
     uint32_t timerBaseClock;

     SystemCoreClockUpdate();
     Board_Init();
     Board_LED_Set(0, false);
     Board_LED_Set(1, false);

     /* Initialize Timer 0 and Timer 1 */
     Chip_TIMER_Init(LPC_TIMER0);


     /* Setup prescale value on Timer 0 to PCLK */
     Chip_TIMER_PrescaleSet(LPC_TIMER0, 0);


     /* Reset timers */
     Chip_TIMER_Reset(LPC_TIMER0);
     Chip_TIMER_Reset(LPC_TIMER1);


     /* Get rate of timer base clock */
     timerBaseClock = Chip_Clock_GetAsyncSyscon_ClockRate();

     /* Setup Timer 0 for a match every 1s */
     Chip_TIMER_SetMatch(LPC_TIMER0, 0, (timerBaseClock / TICKRATE_HZ1));
        
        Chip_TIMER_SetMatch(LPC_TIMER0, 1, (2*(timerBaseClock / TICKRATE_HZ1)));
        

     

     /* Setup both timers to restart when match occurs */
     Chip_TIMER_ResetOnMatchEnable(LPC_TIMER0, 1);
    
       /* Sets external match control (MATn.matchnum) pin control */


       
       Chip_TIMER_ExtMatchControlSet(LPC_TIMER0, 0, TIMER_EXTMATCH_TOGGLE, 0);

       Chip_TIMER_ExtMatchControlSet(LPC_TIMER0, 0, TIMER_EXTMATCH_TOGGLE, 1);

       LPC_TIMER0->PWMC |=(1<<0);
       /* Map P1.16 as MAT0 pin */

       Chip_IOCON_PinMuxSet(LPC_IOCON, 1, 16, (IOCON_FUNC2 | IOCON_DIGITAL_EN | IOCON_INPFILT_OFF));
       Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 6, (IOCON_FUNC3 | IOCON_DIGITAL_EN | IOCON_INPFILT_OFF));
       
       /* Start both timers */
       Chip_TIMER_Enable(LPC_TIMER0);


     /* Wait for timers to generate interrupts (LEDs toggle in interrupt handlers) */
     while (loop) {
          //__WFI();
     }

     return 0;
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍


Have a great day,
Ping

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

元の投稿で解決策を見る

0 件の賞賛
返信
5 返答(返信)
2,142件の閲覧回数
jeremyzhou
NXP Employee
NXP Employee

Hi Chris ONeill.

Please try the amended code.

int loop = 1; /* Prevents unreachable statement warning */

       uint32_t timerBaseClock;

 

       SystemCoreClockUpdate();

       Board_Init();

 

       /* Initialize Timer 0 */

       Chip_TIMER_Init(LPC_TIMER0);

 

       /* Setup prescale value on Timer 0 to PCLK */

       Chip_TIMER_PrescaleSet(LPC_TIMER0, 0);

 

       /* Reset timer */

       Chip_TIMER_Reset(LPC_TIMER0);

 

       /* Get rate of timer base clock */

       timerBaseClock = Chip_Clock_GetAsyncSyscon_ClockRate();

 

       /* Setup Timer 0 for a match every 1s */

       Chip_TIMER_SetMatch(LPC_TIMER0, 0, (timerBaseClock / TICKRATE_HZ1));

       Chip_TIMER_SetMatch(LPC_TIMER0, 1, 2*(timerBaseClock / TICKRATE_HZ1));
 

       /* Setup timer to restart when match occurs */

       Chip_TIMER_ResetOnMatchEnable(LPC_TIMER0, 1);

 

       /* Map P1.16 as MAT0 pin */

       Chip_IOCON_PinMuxSet(LPC_IOCON, 1, 16, (IOCON_FUNC3 | IOCON_DIGITAL_EN | IOCON_INPFILT_OFF));

 

       /* Sets external match control (MATn.matchnum) pin control */

       Chip_TIMER_ExtMatchControlSet(LPC_TIMER0, 0, TIMER_EXTMATCH_TOGGLE, 0);

       Chip_TIMER_ExtMatchControlSet(LPC_TIMER0, 0, TIMER_EXTMATCH_TOGGLE, 1);
 

       /* Start timer */

       Chip_TIMER_Enable(LPC_TIMER0);

 

       while (loop) {

       }

 

       return 0;‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍


Have a great day,
Ping

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 件の賞賛
返信
2,142件の閲覧回数
chrisoneill
Contributor I

Still don't see any output on OM13077 J2 pin 3, which should be P1.16, CT32B0_MAT0.

 Added:

Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 6, (IOCON_FUNC3 | IOCON_DIGITAL_EN | IOCON_INPFILT_OFF));

but no output on J2 pin 1 either, which should be P0.6, CT32B0_MAT1
 

0 件の賞賛
返信
2,143件の閲覧回数
jeremyzhou
NXP Employee
NXP Employee

Hi Chris ONeill.

The PIO1_16 is assigned to the CT32B0_MAT0 when set up the IOCON_FUN2 option (Fig 1).

2017-03-10_13-55-49.jpg

                                                                      Fig 1

Please use the amended code below which can work well (Fig 2)

新建文件2.bmp

                             Fig 2

#define TICKRATE_HZ1 (4)/* 4 ticks per second */

/* main application function (C entry point) */
int main(void)
{
     int loop = 1;     /* Prevents unreachable statement warning */
     uint32_t timerBaseClock;

     SystemCoreClockUpdate();
     Board_Init();
     Board_LED_Set(0, false);
     Board_LED_Set(1, false);

     /* Initialize Timer 0 and Timer 1 */
     Chip_TIMER_Init(LPC_TIMER0);


     /* Setup prescale value on Timer 0 to PCLK */
     Chip_TIMER_PrescaleSet(LPC_TIMER0, 0);


     /* Reset timers */
     Chip_TIMER_Reset(LPC_TIMER0);
     Chip_TIMER_Reset(LPC_TIMER1);


     /* Get rate of timer base clock */
     timerBaseClock = Chip_Clock_GetAsyncSyscon_ClockRate();

     /* Setup Timer 0 for a match every 1s */
     Chip_TIMER_SetMatch(LPC_TIMER0, 0, (timerBaseClock / TICKRATE_HZ1));
        
        Chip_TIMER_SetMatch(LPC_TIMER0, 1, (2*(timerBaseClock / TICKRATE_HZ1)));
        

     

     /* Setup both timers to restart when match occurs */
     Chip_TIMER_ResetOnMatchEnable(LPC_TIMER0, 1);
    
       /* Sets external match control (MATn.matchnum) pin control */


       
       Chip_TIMER_ExtMatchControlSet(LPC_TIMER0, 0, TIMER_EXTMATCH_TOGGLE, 0);

       Chip_TIMER_ExtMatchControlSet(LPC_TIMER0, 0, TIMER_EXTMATCH_TOGGLE, 1);

       LPC_TIMER0->PWMC |=(1<<0);
       /* Map P1.16 as MAT0 pin */

       Chip_IOCON_PinMuxSet(LPC_IOCON, 1, 16, (IOCON_FUNC2 | IOCON_DIGITAL_EN | IOCON_INPFILT_OFF));
       Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 6, (IOCON_FUNC3 | IOCON_DIGITAL_EN | IOCON_INPFILT_OFF));
       
       /* Start both timers */
       Chip_TIMER_Enable(LPC_TIMER0);


     /* Wait for timers to generate interrupts (LEDs toggle in interrupt handlers) */
     while (loop) {
          //__WFI();
     }

     return 0;
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍


Have a great day,
Ping

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 件の賞賛
返信
2,142件の閲覧回数
chrisoneill
Contributor I

Important points were:

use both MAT0 and MAT1

reset timer on MAT1

set PWMC ( = 1 for Timer0)

0 件の賞賛
返信
2,142件の閲覧回数
jeremyzhou
NXP Employee
NXP Employee

Hi Chris ONeill.

Thank you for your interest in NXP Semiconductor products and for the opportunity to serve you.

I'd like to run the above code by myself, and to replicate the issue.

I'll reply later after I work it out.
Have a great day,
Ping

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 件の賞賛
返信