#1
Сообщение
dmitriym73316 » 20.02.2023{, 20:37}
помогите с созданием блока формирования синуса .не получается самому создать. имеется скетч.
желательно добавить входы en и value.
#include <TimerOne.h>
#include "sineTable.h"
int counter;
void setup() {
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
Timer1.initialize(100); // 100uS
Timer1.pwm(9, 100);
Timer1.pwm(10, 100);
Timer1.attachInterrupt(sineWave);
}
void loop() {
}
void sineWave() {
counter++;
if(counter == 200) counter = 0;
if (counter < 100) {
Timer1.setPwmDuty(9, sineVal[0][counter]);
Timer1.setPwmDuty(10, 0);
}
else {
Timer1.setPwmDuty(9, 0);
Timer1.setPwmDuty(10, sineVal[0][counter - 100]);
}
}
####################################
#ifndef SINETABLE_H
#define SINETABLE_H
//---- sineTable.h ----
const int sineVal[][100] = {
// Peak Value = 800
{0,25,50,75,100,125,150,175,199,223,247,271,294,318,341,363,385,407,429,450,470,490,510,529,548,566,583,600,616,632,647,662,675,689,701,713,724,734,744,753,761,768,775,781,786,790,794,796,798,800,800,800,798,796,794,790,786,781,775,768,761,753,744,734,724,713,701,689,675,662,647,632,616,600,583,566,548,529,510,490,470,450,429,407,385,363,341,318,294,271,247,223,199,175,150,125,100,75,50,25,},
};
#endif