Добрый день! На форуме нашел код генерации ШИМ синуса 60 гц. Можете помочь/подсказать как изменить частоту на 1000гц ?
uint16_t sine_wave[512] = {
0x100,0x103,0x106,0x109,0x10c,0x10f,0x112,0x115,
0x119,0x11c,0x11f,0x122,0x125,0x128,0x12b,0x12e,
0x131,0x134,0x137,0x13b,0x13e,0x141,0x144,0x147,
0x14a,0x14d,0x150,0x153,0x156,0x159,0x15b,0x15e,
0x161,0x164,0x167,0x16a,0x16d,0x170,0x172,0x175,
0x178,0x17b,0x17d,0x180,0x183,0x186,0x188,0x18b,
0x18d,0x190,0x193,0x195,0x198,0x19a,0x19d,0x19f,
0x1a2,0x1a4,0x1a6,0x1a9,0x1ab,0x1ad,0x1b0,0x1b2,
0x1b4,0x1b6,0x1b9,0x1bb,0x1bd,0x1bf,0x1c1,0x1c3,
0x1c5,0x1c7,0x1c9,0x1cb,0x1cd,0x1cf,0x1d0,0x1d2,
0x1d4,0x1d6,0x1d7,0x1d9,0x1db,0x1dc,0x1de,0x1df,
0x1e1,0x1e2,0x1e4,0x1e5,0x1e6,0x1e8,0x1e9,0x1ea,
0x1ec,0x1ed,0x1ee,0x1ef,0x1f0,0x1f1,0x1f2,0x1f3,
0x1f4,0x1f5,0x1f6,0x1f7,0x1f7,0x1f8,0x1f9,0x1f9,
0x1fa,0x1fb,0x1fb,0x1fc,0x1fc,0x1fd,0x1fd,0x1fd,
0x1fe,0x1fe,0x1fe,0x1ff,0x1ff,0x1ff,0x1ff,0x1ff,
0x1ff,0x1ff,0x1ff,0x1ff,0x1ff,0x1ff,0x1fe,0x1fe,
0x1fe,0x1fd,0x1fd,0x1fd,0x1fc,0x1fc,0x1fb,0x1fb,
0x1fa,0x1f9,0x1f9,0x1f8,0x1f7,0x1f7,0x1f6,0x1f5,
0x1f4,0x1f3,0x1f2,0x1f1,0x1f0,0x1ef,0x1ee,0x1ed,
0x1ec,0x1ea,0x1e9,0x1e8,0x1e6,0x1e5,0x1e4,0x1e2,
0x1e1,0x1df,0x1de,0x1dc,0x1db,0x1d9,0x1d7,0x1d6,
0x1d4,0x1d2,0x1d0,0x1cf,0x1cd,0x1cb,0x1c9,0x1c7,
0x1c5,0x1c3,0x1c1,0x1bf,0x1bd,0x1bb,0x1b9,0x1b6,
0x1b4,0x1b2,0x1b0,0x1ad,0x1ab,0x1a9,0x1a6,0x1a4,
0x1a2,0x19f,0x19d,0x19a,0x198,0x195,0x193,0x190,
0x18d,0x18b,0x188,0x186,0x183,0x180,0x17d,0x17b,
0x178,0x175,0x172,0x170,0x16d,0x16a,0x167,0x164,
0x161,0x15e,0x15b,0x159,0x156,0x153,0x150,0x14d,
0x14a,0x147,0x144,0x141,0x13e,0x13b,0x137,0x134,
0x131,0x12e,0x12b,0x128,0x125,0x122,0x11f,0x11c,
0x119,0x115,0x112,0x10f,0x10c,0x109,0x106,0x103,
0x100,0xfc,0xf9,0xf6,0xf3,0xf0,0xed,0xea,
0xe6,0xe3,0xe0,0xdd,0xda,0xd7,0xd4,0xd1,
0xce,0xcb,0xc8,0xc4,0xc1,0xbe,0xbb,0xb8,
0xb5,0xb2,0xaf,0xac,0xa9,0xa6,0xa4,0xa1,
0x9e,0x9b,0x98,0x95,0x92,0x8f,0x8d,0x8a,
0x87,0x84,0x82,0x7f,0x7c,0x79,0x77,0x74,
0x72,0x6f,0x6c,0x6a,0x67,0x65,0x62,0x60,
0x5d,0x5b,0x59,0x56,0x54,0x52,0x4f,0x4d,
0x4b,0x49,0x46,0x44,0x42,0x40,0x3e,0x3c,
0x3a,0x38,0x36,0x34,0x32,0x30,0x2f,0x2d,
0x2b,0x29,0x28,0x26,0x24,0x23,0x21,0x20,
0x1e,0x1d,0x1b,0x1a,0x19,0x17,0x16,0x15,
0x13,0x12,0x11,0x10,0xf,0xe,0xd,0xc,
0xb,0xa,0x9,0x8,0x8,0x7,0x6,0x6,
0x5,0x4,0x4,0x3,0x3,0x2,0x2,0x2,
0x1,0x1,0x1,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x1,0x1,
0x1,0x2,0x2,0x2,0x3,0x3,0x4,0x4,
0x5,0x6,0x6,0x7,0x8,0x8,0x9,0xa,
0xb,0xc,0xd,0xe,0xf,0x10,0x11,0x12,
0x13,0x15,0x16,0x17,0x19,0x1a,0x1b,0x1d,
0x1e,0x20,0x21,0x23,0x24,0x26,0x28,0x29,
0x2b,0x2d,0x2f,0x30,0x32,0x34,0x36,0x38,
0x3a,0x3c,0x3e,0x40,0x42,0x44,0x46,0x49,
0x4b,0x4d,0x4f,0x52,0x54,0x56,0x59,0x5b,
0x5d,0x60,0x62,0x65,0x67,0x6a,0x6c,0x6f,
0x72,0x74,0x77,0x79,0x7c,0x7f,0x82,0x84,
0x87,0x8a,0x8d,0x8f,0x92,0x95,0x98,0x9b,
0x9e,0xa1,0xa4,0xa6,0xa9,0xac,0xaf,0xb2,
0xb5,0xb8,0xbb,0xbe,0xc1,0xc4,0xc8,0xcb,
0xce,0xd1,0xd4,0xd7,0xda,0xdd,0xe0,0xe3,
0xe6,0xea,0xed,0xf0,0xf3,0xf6,0xf9,0xfc
};
void setup(){
pinMode(9,OUTPUT);
pinMode(10,OUTPUT);
TCCR1A = (1<<COM1A1)|(1<<COM1B1)|(1<<COM1B0)|(1<<WGM11);
TCCR1B = (1<<WGM12)|(1<<CS10); //Mode6 Fast PWM, 9-bit TOP 0x01FF ; DIV 1
TIMSK1 = 1<<TOIE1;
OCR1A=OCR1B=0;
}
ISR (TIMER1_OVF_vect) {
static uint16_t n=0;
n=n&511;
OCR1A=OCR1B=sine_wave[n];
n++;
}
void loop(){
}
Спасибо!