Using your code I can reach the high frequency as I want, but I cannot modulate the Duty Cycle by an analog road for example, it is fixed at the value selected in the code. How could I do that? it seems that other functions are disabled with this code.
HermannSW:
Found "Setting High Speed PWM on ATTiny85":
c - Setting high speed PWM on ATtiny85 - Stack Overflow
Adapted for Arduino IDE I measured up to 676.7kHz with "OCR1C = 123;".
123*676.7
83234.1
127648
82296
141590.8
83302.8
159*524.4
83379.6
This is from comment of sketch below, not sure why I measured 1.3 times as much:
// Set PWM TOP value - counter will count and reset
// after reaching this value
// OCR1C
// 400Khz 159
// 450khz 141
// 500khz 127
400159
63600
450141
63450
127*500
63500
Hermann.
//#include <avr/io.h>
//#include <avr/interrupt.h>
void setup()
{
PORTB = 0; //Reset values on port B
// After setting up the timer counter,
// set the direction of the ports to output
DDRB |= (1<<PB1) | (1<<PB0); // Set the direction of PB1 to an output
// PLLCSR - PLL control and status register:
// PLL is a clock multiplier - multiplies system 8Mhz by 8 to 64Mhz
// PLL is enabled when:PLLE bit is enabled,
// CKSEL fuse is programmed to 0001. This clock is
// switched off in sleep modes!
PLLCSR |= (1<<PLLE); // PLL enable
// Wait until the PLOCK bit is enabled
// before allowing the PCK to be enabled
// WaitForPLOCK();
// unsigned int i = 0;
while ((PLLCSR & (1<<PLOCK)) == 0x00)
{
// Do nothing until plock bit is set
}
PLLCSR |= (1<<PCKE); // Enable asynchronous mode, sets PWM clock source
TCCR1 =
(1<<CTC1) | //enable pwm
(1<<PWM1A) | // set source to pck
(1<<(CS10)) | // clear the pin when match with ocr1x
(1<<COM1A1);
GTCCR = (1<<PWM1B) | (1<<COM1B1);
// Set PWM TOP value - counter will count and reset
// after reaching this value
// OCR1C
// 400Khz 159
// 450khz 141
// 500khz 127
OCR1C = 159;
//enable Timer1 OVF interrupt
TIMSK = (1<<OCIE1A) | (1<<TOIE1);
sei();
//This should set the duty cycle to about 75%
OCR1A = 120;
}
void loop() {
}