Hi, I have little problems with timers in LPC1768. I need to start timer2 because I use timer0 and timer1. When I want to configure and start timer2 all program doesn't start and I see nothing reaction - white display and no reaction. I have question: can I use more timers than 2? How many timers can I use ? And the second problem - I'd like to turn off one of the timers. How can I do it ? I understand that I must change pins on TCR register, but when I set bit 0 or 1 from documentation I turned off timer but I can't turn on again...I can turn off only once. I don't understand it.
LPC_TIM1->TCR |= 1 << 0; - start timer LPC_TIM1->TCR |= 0 << 0; - turn off timer ? It doesn't work...
I also tried LPC_TIM1->TCR |= 1 << 1 but then timer didn't start again when I set LPC_TIM1->TCR |= 1 << 0 again. I think that you understand what I mean. Thanks for help.
"LPC_TIM1->TCR |= 0 << 0; - turn off timer ? It doesn't work..."
Time to read up on the operators in C.
Do you really think that or:ing a zero will clear that bit?
You do know the logic table for bitwise or?
0 or 0 => 0 0 or 1 => 1 1 or 0 => 1 1 or 1 => 1
So when the bit in the register is 1 and you or with 0, you still end up with 1.
Maybe, just maybe, bitwise or isn't a good route if you want to clear a bit...
Should I use and operator for clear this bit? What about using a few timers ? For example using 3 timers at once?
You use whatever operator gives the result that you require!
And, of course, you need the appropriate operands to go with that operator!
We're talking basic logic here; not even specific to 'C' - let alone Keil or LPC1768
"What about using a few timers ?"
What about it?
"For example using 3 timers at once?"
You just do the same thing - three times!
Perhaps this will help: www.kpsec.freeuk.com/gates.htm
aka "Boolean algebra"
View all questions in Keil forum