The following TCNT1 based sketch is uploaded in UNO to generate 5 Hz PWM signal (test signal to see activities on LED) on Ch-A (non inverting) and Ch-B (inverting) in Mode-14 Fast PWM. Ch-A (DPin-9) is working showing activities; but, Ch-B (DPin-10) is not working showing constant HIGH state. Would appreciate if someone checks what RONG I am doing here. (The registers' bit lay out are given below for quick reference.)
1. Both channels are working fine in non-inverting mode with the following COM1x bits settings:
COM1A1 = 1, COM1A0 = 0
COM1B1 = 1, COM1B0 = 0
2. The channels are found not working in inverting mode with the following CM1x bits settings:
COM1A1 = 1, COM1A0 = 1
COM1B1 = 1, COM1B0 = 1
Even with all constants U/UL (unsigned/unsigned long), Ch-A works in non-inverting mode; Ch-B does not work in inverting mode. However, both channels work well in non-inverting mode.
I viewed both channels with my scope and found that the duty cycle is far away from 50%. That makes one channel almost LOW (or blink) while the other one is almost HIGH, not recognized as blinking. I could not really get a 50% cycle based on the given sketch.
Has anybody checked what the TimerOne library does with FastPWM mode?
The order of setup for the timer matters. If you set the outputs and the mode before giving specific values and starting the timer the output is as expected. That is, alternating flashes at 5 Hz on two leds attached to 9 and 10.
I knew that there was a pitfall but couldn't remember where it was.
In the original sketch the mode 2 was initialized that trims the immediately following compare values to 9 bits. Only after that mutilation the mode 14 was established.
1. Great! Great!!
Your sketch of post #9 is perfectly working! Frequency is reduced to 1 Hz and the LEDS are visibly alternately flashing. Moreover, both channels are working in non-invert and invert modes.
2.
The sequences of TC1 intializations: (1) Reset TCCR1A and TCCR1B (2) Set COM1x Bits for Ch-A (3) Set COM1x Bits for Ch-B (4) Set the Wave form Mode (5) Set the values for TOP and duty cycles. (6) Start TC1 with required prescale/division factor.
3. Let us note down the above sequence of initializations as shown by @cattledog. Humble appreciation towards the time that @cattledog has spent to resolve the case.
But the following figure (Fig-1) shows that the signals Ch-A and Ch-B are of opposite polarity and synchronized. They must be synchronized meaning when Ch-A is rising , Ch-B must be falling at the same instant for them to be useful in practical applications.
2. To verifyy that the signals are indeed of opposite and synchronized, let us carry out the following experiment by measuring the time interval (500 ms) between the falling edges of signals marked Ch-A and Ch-B in Fig-1. Signals at Ch-A (non-invert) and Ch-B (invert) are of opposite polarity and synchronized, which being generated using TC1 in Fast PWM Mode-14. The PWM signals are simulating the sensor signals very closely.
=======================
Total Count = 7999748
Time between two falling edges = 499.98 ms
=======================
Let us change the frequency of Ch-A/B signal to 2 Hz and check that the display shows: ~-250 ms. Output:
================================================
Total Count = 3999748
Time between two falling edges = 249.98 ms
================================================