Question about timer1

Hi!
I have made a code that uses the timer 1 to create a 60hz signal on pin 10 with the duty cycle of 0.03%

  void setup() {
   TCCR1A =  _BV(COM1B1) | _BV(WGM11) | _BV(WGM10);
   TCCR1B = _BV(WGM12) |_BV(WGM13) | _BV(CS12);
   OCR1A = 1025; //16000000hz/256hz/60hz  ≈ 1025
   pinMode(10, OUTPUT);
  }
  void loop() {
  }

But for some reason I can't even get any kind of signal out of that port. Can someone help me with my code?
Edit: Include the basic absolute minimum amount of code for an arduino project.

But for some reason I can't even get any kind of signal out of that port. Can someone help me with my code?

You're more likely to get something out of the port if you actually write some code....

PerryBebbington:
You're more likely to get something out of the port if you actually write some code....

What kinda code? Shouldn't enabling COM1B1 Register manipulate the port 10?

What is the basic, absolute minimum code for an Arduino project?

Edited the main post.

You have WGM set to 16, fast PWM with OCR1A as TOP.

You have COM1B1 set to 1,

Clear OC1A/OC1B on Compare Match, set
OC1A/OC1B at BOTTOM (non-inverting mode)

But you haven't set OCR1B, so it's at it's default value of 0.

I suspect what's happening is that the compare match happens at a count of 0, so it spends all it's time with the bit cleared (low).

if you want a 50% duty cycle square wave, set OCR1B to half of what you set OCR1A (TOP) to.

piuhis3:
Edited the main post.

Right, that's better.

Please post ALL your code in future, you are far more likely to get quick and helpful answers that way instead of wasting both your time and the time of people trying to help you.

I don't know the answer to your question.

DrAzzy:
You have WGM set to 16, fast PWM with OCR1A as TOP.

You have COM1B1 set to 1,

Clear OC1A/OC1B on Compare Match, set
OC1A/OC1B at BOTTOM (non-inverting mode)

But you haven't set OCR1B, so it's at it's default value of 0.

I suspect what's happening is that the compare match happens at a count of 0, so it spends all it's time with the bit cleared (low).

if you want a 50% duty cycle square wave, set OCR1B to half of what you set OCR1A (TOP) to.

Good theory, but unfortunately it doesn't seem to work. Here is my new code.

   TCCR1A =  _BV(COM1B1) | _BV(WGM11) | _BV(WGM10);
   TCCR1B = _BV(WGM12) |_BV(WGM13) | _BV(CS12);
   OCR1A = 1025; //16000000hz/256hz/60hz  ≈ 1025
   OCR1B = 512;
   pinMode(10, OUTPUT);

hmmmmm..... I don't see the issue, then. And this is an atmega328p? (eg, uno/nano/pro mini/other '328p based board)

(btw - your comment should be written //16000000hz/256/60hz - the prescaler has no units, and this way the hz's cancel so your result is, as you want, dimensionless - ofc this has nothing to do with your problem, just something that bugs me as someone whose education was very heavy on the importance of dimensional analysis for sanity validation)

You aren’t going to get an exact 60Hz since 16000000 doesn’t divide evenly by 60. When I do the timer math I get a prescale of 8 and a count of 33,333 and 1/3rd. If you want fewer steps of PWM you can use a prescale of 256 and count of 1041.

Well, he says he's getting nothing not that he's getting wrong output. So we should figure that out first :stuck_out_tongue:

Ok, I got it to work, it turns out there was just a loose connection in my circuit. Thanks for all of your help! And it doesn't matter that it isn't 100% exact 60hz.