Differential Clock Output in CTC Mode

I am wondering if I can invert the output of D10 (0C1B), so it is 180 degrees out of phase with D9 (0C1A). Using Arduino Uno Rev 3.
Thanks in advance...
my code:


#define myOutputPin 9
#define mynotOutputPin 10

void setup ()
{
  pinMode (myOutputPin, OUTPUT);
  pinMode (mynotOutputPin, OUTPUT); 

  
  TCCR1A = 0;
  TCCR1B = 0;
  TCNT1  = 0;
  OCR1A = 80;   //  for 100KHz
  TCCR1A |= (1 << COM1A0);   
  TCCR1A |= (1 << COM1B0);   
  TCCR1B |= (1 << WGM12);    
  TCCR1B |= (1 << CS10);     
}

Use Fast PWM Mode.

Yes. You've already done that. You have set D9 and D10 to toggle at the top of the count (COM1A0 and COM1B0 set). Just digitalWrite(9, LOW); digitalWrite(10, HIGH); in setup(). Since they both toggle at the same time they will remain 180° out of phase.

Edit:
Also, set OCR1B to the same value as OCR1A.

The data sheet only mentions OC1A for output in CTC mode, not the B channel. Did I miss something?

I think it will work if OCR1B is set the same as OCR1A. The datasheet says that the COM1B0 and COM1B1 bits work in CTC mode.

Hi, @crucialaudio

Have you tried it?

Tom... :smiley: :+1: :coffee: :australia:

(post deleted by author)

DrDietrtrich - Thank you very much I will experiment with Fast PWM mode..
In regards to your second comment I could not find it in the data sheet either but was able to activate D10. Hence one of the reasons for my post.
Thanks again!

" Yes. You've already done that. You have set D9 and D10 to toggle at the top of the count (COM1A0 and COM1B0 set). Just digitalWrite(9, LOW); digitalWrite(10, HIGH); in setup(). Since they both toggle at the same time they will remain 180° out of phase.

Edit:
Also, set OCR1B to the same value as OCR1A"

Thank you John! I'm going to try that when I get back to the laboratory...
COM1B0 outputs the same rate as set in OCR1A, but the cool thing is I can set a different rate in OCR1B. That yields different frequencies on the same timer.

In the datasheet I have (DS40002061A) it's on Page 140:

When the OC1A or OC1B is connected to the pin, the function of the COM1x1:0 bits is dependent of the WGM13:0 bits setting. Table 16-1 shows the COM1x1:0 bit functionality when the WGM13:0 bits are set to a Normal or a CTC mode (non-PWM).

Table 16-1. Compare Output Mode, non-PWM

COM1A1/COM1B1 COM1A0/COM1B0 Description
0 0 Normal port operation, OC1A/OC1B disconnected.
0 1 Toggle OC1A/OC1B on Compare Match.
1 0 Clear OC1A/OC1B on Compare Match (Set output to low level).
1 1 Set OC1A/OC1B on Compare Match (Set output to high level).

TomGeorge - Yes sir, I had it running but both pins had the same phase relationship. It will be perfect after I invert D10's signal.

No, you can't. The frequency of both is controlled by OCR1A. You can set OCR1B to a lower value so it toggles earlier in the cycle if you want a phase difference less than 180°.

Johnwasser,
"No, you can't. The frequency of both is controlled by OCR1A. You can set OCR1B to a lower value so it toggles earlier in the cycle if you want a phase difference less than 180°."

I will double check when I get to the lab later, but last night I'm pretty certain I achieved that. And of course the timing was related. It was a bit of a late night... lol
Stay tuned and thanks again for your assistance!!!