Академический Документы
Профессиональный Документы
Культура Документы
h>
//For testing
int freqInput = 100; //10-10000 Hz (I wanted that range only)
int dutyCycleInput = 70; //1-65535
void setup()
{
InitTimersSafe();
}
void loop()
{
//Get inputs from either serial or through pot
//So we have Frequency and Duty cycle in variables 'freqInput' &
'dutyCycleInput' respectively in int
SetPinFrequencySafe(outputPin, freqInput );
pwmWriteHR(outputPin, dutyCycleInput );
}
/*
#include <PWM.h>
void setup()
{
Serial.begin(115200);
in_String.reserve(200);
InitTimersSafe();
}
void loop()
{
int32_t tempr = 0;
char * pEnd;
if(debug_osm) {
uint32_t currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
phaseShift();
}
}
serialEvent();
if( end_input) {
char cmd = in_String[0];
in_String[0] = '+';
GTCCR |= ((1<<TSM)|(1<<PSRASY)|(1<<PSRSYNC));
GTCCR &= ~(1<<TSM);
pinMode(13, OUTPUT);
digitalWrite(13, HIGH);
}
}
//GTCCR |= ((1<<TSM)|(1<<PSRASY)|(1<<PSRSYNC));
GTCCR |= (1<<TSM);
in_String = "";
end_input= false;
}
}
void serialEvent() {
while (Serial.available()) {
char inChar = (char)Serial.read();
in_String += inChar;
if (inChar == '\n') {
end_input= true;
}
}
}
void phaseShift() {
static uint16_t phase_loc = 0;
uint16_t tempr = 0;
//GTCCR |= ((1<<TSM)|(1<<PSRASY)|(1<<PSRSYNC));
GTCCR |= (1<<TSM);
// GTCCR |= _BV (TSM);
TCNT1 = 0;
TCNT3 = tempr;