Invert Timer output

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

Invert Timer output

530 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by rickta59 on Fri May 10 16:33:44 MST 2013

I'm trying to figure out how to use the timers properly. I using something like the following code to end up with a 20msec period with a 1msec duty. Typical of what you might find with an analog servo. I can't figure out how to invert the signal without using hardware or writing an my own interrupt handler to toggle gpio pins. Is it possible using PWM to have the timer start high and then go low when the match is reached?


<pre><code>    // enable clock to 16bit timers (3.5.14)
    LPC_SYSCON->SYSAHBCLKCTRL |= (1 << 7);

    LPC_IOCON->PIO0_8 |= (1<<1);        // output MR0

    LPC_TMR16B0->PR = (F_CPU/1000000)-1; // set prescaler to 1 us

    LPC_TMR16B0->MR3 = 20000;           // 20msec
    LPC_TMR16B0->MR0 = 1000;            // 1msdc

    // use MR3 for period, use MR0, MR1 as the duty cycle
    LPC_TMR16B0->MCR |= (0x01 << 10);

    // enable PWM for MAT0, MAT1
    LPC_TMR16B0->PWMC |= 0b11;             // enable pwm P0.8/P0.9

    NVIC_EnableIRQ(TIMER_16_0_IRQn);
 
    LPC_TMR16B0->TCR = 0x1;
</code>
</pre>

The code above does what I want, except it starts low and goes high on the match. I realize I could use 19000 for the match and then have it go high for the last 1msec, however that doesn't start at the beginning of the period.


I've searched for sample servo code but didn't find anything.


-rick

Labels (1)
0 Kudos
Reply
1 Reply

493 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by rickta59 on Mon May 13 05:48:13 MST 2013

Well it doesn't seem like there are any software answers to this. To solve this problem I'm going to use a SN74HC04N. This solves the inverted signal problem and an added bonus is that it brings the signal level up to 5volts and makes the servo happy.


-rick

0 Kudos
Reply