If i use line "TCCR0B = TCCR0B & 0b11111000 | 0b001;" it change PWM frequency on port D0 and D1 of ATtiny85 (i read that on forum). What if i want to change PWM frequency on port D3 and D4? I tried with line "TCCR1B = TCCR1B & 0b11111000 | 0b001;" but it doesn't work. On ATmega328 line TCCR0B change PWM on port 5 and 6, TCCR1B on port 9 and 10 and TCCR2B on port 11 and 3, but not with ATtiny85.So, how to change PWM on port D3 and D4?
Tiny85 doesn't have the same timers as a Mega328.Look for TCCR1 in the datasheet.
Since ATtiny85 have 2 PWM outputs (PB0 and PB1) it probably have one PWM timer (TCCR1). This timer has two output compare registers that control the PWM (TCCR0A and TCCR0B).. Is that correct?
TCCR0A = TCCR0A & 0b11111000 | 0x01; <-- for PB0TCCR0B = TCCR0B & 0b11111000 | 0x01; <-- for PB1
It has three, two on timer 0 and one on timer 1. The number in the register name tells you which timer the register belongs to, so anything with a '1' in it (eg TCCR1) doesn't refer to timer 0.
TCCR0A has no effect on timer0 frequency.TCCR0B does - look at CS02, CS01 and CS00 in the datasheet.
Ok, TCCR0A and TCCR0B for timer 0 (first PWM port PB0) and TCCR1 for timer 1 (second PWM port PB1). So, if i change TCCR0B it will affect only on PWM frequency of first PWM port (PB0)?
If i look into table from datasheet for CS02, CS01 and CS00 this line should look like this "TCCR0B = TCCR0B & 0b11111001 | 0x01;" for clk/no prescaling? But how can i set PWM frequency? What in that case mens "setting" 0x01?
it means timer0 counts at the speed of the CPU clock (it's not divided by anything). You can divide by 1, 8, 64, 256, etc., using CS02, CS01 and CS00.
If your chip is running at 8MHz then 0x01 in TCCR0B means your PWM frequency is 8000000/256 = 31.24kHz
You set the pulse width by changing OCR0A and OCR0B.
8000000/256 = 31.24kHz but why "0x01" (binary 0000 0001) means 256? Is there also a table for that 0x01 means mode "divide with 256"?
The timer is counting 0..255, so repeats every 256 clock cycles, so its output is clock / 256 ??
analogWrite(fet, 128);delay(3000);analogWrite(fet, 255);delay(3000);
I am driving fan with P-Channel FET and transistor. FET is SUD50P04 and transistor is 2n3904.
Why would you need 32kHz PWM for a fan? A mechanical device like a fan isn't going to respond any better to 32kHz than 100Hz.
Ok, now that's funny. I set frequency to 30 Hz and annoying noise disappeared!
Do you think that could be because it's getting down to the lower end of the range you can hear (approx 20Hz in adults) so it's less intrusive?