if I have to do a toggle for 50% duty cycle, one needs to set an OCR value. How is calculation done?
To get 50% duty cycle, you'd set an OCR to half of the top counter value "TOP." TOP is either the maximum counter value limited by hardware (255 or 65535 depending on whether its an 8bit or 16bit timer), OR the value of another OCR register, depending on the timer mode. If you want a 125kHz square wave output, you'd HAVE to use one of the modes with an OCR register as top, because 125kHz*256 is 32MHz, which is faster than the timer on an Uno will go.
You could set the prescaler to /16, OCRA to 7, and OCRB to 3 or prescaler to /1, OCRA to 127 and OCRB to 63; I think those will give you 125kHz...
Do I have to set both ICR and OCR values?
AFAIK, they operate entirely separately. Are you thinking that "Input capture" will capture the state of a pin at particular count values? That's NOT what it does - it captures the counter value when there is a pin state change.
Gathering data from other threads, I gather you're trying to provide clock for some sort of Manchester Data provider?
- Is 125kHz the "carrier" frequency, or the data rate?
- In most Manchester encoding examples, there is a clock that is 2x the data rate, but you showed a diagram where you have 32 clocks per bit (or half-bit)?
- Manchester gets the data bit value from the direction of the data bit transition in the middle of the data period. I'm not sure that using ICR (which gives you time between transitions) is going to be helpful. I guess "long" means the data bit is different than the last bit, while "short" means it's the same.
- I thought that a point of manchester encoding was that you can derive the clock from the data stream. Why are YOU generating the 125kHz?
- If you have 8 or 128 clocks per data bits, and are using OCRA to generate that clock, you can certainly use OCRB to check the databit at (or slightly past) the midpoint. (OCRA as top, OCRB as interrupt, read the bit in the ISR. Or poll, except then you don't really need the OCR to help.)