realy sorry for my bad english!!!
there wasn't problem in compiler but in my code. now I found solution on some forum.
I didn't post the code cause I didn't know there to start and everithing what I wrote was trash. but your link solved it all.
thanks a lot for your help.
my code:
#define FTM0_CH0_PIN 22
#define FTM0_CH1_PIN 23
#define FTM0_CH2_PIN 9
#define FTM0_CH3_PIN 10
#define FTM0_CH4_PIN 6
#define FTM0_CH5_PIN 20
#define FTM0_CH6_PIN 21
#define FTM0_CH7_PIN 5
#define FTM1_CH0_PIN 3
#define FTM1_CH1_PIN 4
#define FTM2_CH0_PIN 32
#define FTM2_CH1_PIN 25
const int ledPin = 13;
const int btn = 1;
const int FreqOutPin = 5;
bool bFreqState = true; //true=2Hz, false=100Hz
void setup()
{
pinMode(ledPin, OUTPUT);
pinMode(FreqOutPin, OUTPUT);
pinMode(btn, INPUT_PULLUP);
analogWriteFrequency(FreqOutPin, 2); // 2Hz
attachInterrupt(btn, isrBtn, FALLING);
}
void loop()
{
analogWrite(FreqOutPin, 25); //strieda 10% z 255
}
void isrBtn()
{
cli();
if( bFreqState )
{
bFreqState = false;
analogWriteFrequencySlow(FreqOutPin, 100); //switch to 100Hz
}
else
{
bFreqState = true;
analogWriteFrequencySlow(FreqOutPin, 2); //switch to 2Hz
}
delay(600);
sei();
}
void analogWriteFrequencySlow(uint8_t pin, float frequency)
{
uint32_t prescale, mod;
float minfreq;
for (prescale = 0; prescale < 7; prescale++) {
minfreq = (float)(31250 >> prescale) / 65536.0f;
if (frequency >= minfreq) break;
}
mod = (float)(31250 >> prescale) / frequency - 0.5f;
if (mod > 65535) mod = 65535;
if (pin == FTM1_CH0_PIN || pin == FTM1_CH1_PIN) {
FTM1_SC = 0;
FTM1_CNT = 0;
FTM1_MOD = mod;
FTM1_SC = FTM_SC_CLKS(2) | FTM_SC_PS(prescale);
} else if (pin == FTM0_CH0_PIN || pin == FTM0_CH1_PIN
|| pin == FTM0_CH2_PIN || pin == FTM0_CH3_PIN
|| pin == FTM0_CH4_PIN || pin == FTM0_CH5_PIN
#ifdef FTM0_CH6_PIN
|| pin == FTM0_CH6_PIN || pin == FTM0_CH7_PIN
#endif
) {
FTM0_SC = 0;
FTM0_CNT = 0;
FTM0_MOD = mod;
FTM0_SC = FTM_SC_CLKS(2) | FTM_SC_PS(prescale);
}
#ifdef FTM2_CH0_PIN
else if (pin == FTM2_CH0_PIN || pin == FTM2_CH1_PIN) {
FTM2_SC = 0;
FTM2_CNT = 0;
FTM2_MOD = mod;
FTM2_SC = FTM_SC_CLKS(2) | FTM_SC_PS(prescale);
}
#endif
}