cancel
Showing results for 
Search instead for 
Did you mean: 

Where do I read OCxREF?

PMath.4
Senior III

I need to set up a PWM without an output pin but be able to read the state of the "virtual" signal. In the reference manual this state is referred to as OCxREF (OC1REF, OC2REF etc.). However, I'm clearly going senile as I can't find this in any of the timer registers. It is referred to in many places and I can see how to force the status but I just need to read it.

I'm missing something as usual but help would be appreciated.

3 REPLIES 3

That signal is not directly available to the user.

I can't even think of a simple way how to observe it indirectly (other than output it to a pin and read back its state). OCxRef can be output as TRGO, then input to some other module and observe its effect, e.g. set a slave timer to gated mode and by consecutive reading of CNT judge whether it's running or not (with pitfalls ahead).

The idea is, that once you have full control over its state in software, you *know* its state at any moment implicitly.

Maybe you want to tell us why would you want to read it.

JW

PMath.4
Senior III

That seems a bizarre omission so I'll have to use some wasteful maths as follows:

PWM mode:

TIMx_CCRy compared to TIMx_CNT

CNT < CCRy=> output active

CNT ≥ CCRy=> output inactive

Reading a register and using a bit of it is relatively computationally intensive, too.

Try both - reading CNT, comparing to CCR (which you might have cached in faster RAM variable) and do some action; and reading any register, checking one particular bit of it, and do some action. Compare the resulting disasm.

JW