I am planning to use an STM8 Timer2 channel as an output. Here is the basic idea:
1. Wait some period of time.
2. Set the channel output pin high.
3. Read the timer count, add 400, and write to the compare register.
4. When the count and compare match (400 ticks) later, the output pin toggles automatically.
5. Catch the interrupt and set a new compare value.
Bits OC1M in TIM2_CCMR1 set the behavior of the output pin.
Using 101 is "Force active level - OC1REF is forced high". That takes care of (2) above.
But I want to use 011 "Toggle - OC1REF toggles when TIM2_CNT = TIM2_CCR1" so that the pin will toggle automatically.
My datasheet "DocID14587 Rev 14" does not seem to address this.
Will this work?
1. Set OC1M in TIM2_CCMR1 to 101 to set the output pin to high. Then, immediately after:
2. Set OC1M in TIM2_CCMR1 to 011 to toggle the pin (to low) when the count matches (400 ticks later).
To ask this a different way, when I write 011 for "toggle", does it leave the current pin value unchanged? (Until the count and compare match.)
I am suspicious about *assuming* any behavior that is not well documented.
For the curious, this is serial bit-banging and I would like the timer channel to handle the pin timing, and avoid jitter from interrupt latency.
Thanks!