I currently trying to change the PWM frequency from the the standard 490 Hz to something else, Literally something else.
I previously used a timer1
library available from the Arduino, but became annoyed by it an began setting up things manually.
#include "test.h"
test::test()
{
pinMode(10,OUTPUT);
//Timer1 setup1 Interrup at 1hz
cli(); // Stop interrupts
TCCR1A = 0;
TCCR1B = 0;
TCNT1 = 0;
OCR1A = 15624; // Compare register value = cpu_fre/(interrupt_freq*prescaler)-1 (must be <65536)
TCCR1B |= (1 << WGM12);
TCCR1B |= (1 << CS12)| (1 << CS11) | (1 << CS10);
TIMSK1 |= (1 << OCIE1A);
sei(); //allow interrupts
}
ISR(TIMER1_COMPA_vect)
{
digitalWrite(10,!digitalRead(10));
}
here is the main
#include "test.h"
test test1;
void setup()
{
Serial.begin(230400);
// put your setup code here, to run once:
}
void loop()
{
}
This should should create an interrupt each 1 Hz changing the state of the pin. but instead creates a 490 Hz PWM signal...
Changing the prescaler or OCR1A only changes the duty cycle of the signal, and not the frequency itself..
What I am doing wrong here?