Hello all.I will to change this code from 5Hz to in 200Hz output signal.
How can I do this, whitch line's have I to updata in the code?
It is creat if any me will help.
SquareWaveInverter.ino (917 Bytes)
Hello all.I will to change this code from 5Hz to in 200Hz output signal.
How can I do this, whitch line's have I to updata in the code?
It is creat if any me will help.
SquareWaveInverter.ino (917 Bytes)
Can't see your code.
If you post your code as directed by the how to use this forum-please read stickies, everyone can see the code and help you.
The code is using the registers to set up timer1 to fire the interrupt routines, if you don't know how to do so, you would be better of using the timer.h library and figure it out by the examples that come with that.
Here is his code:
bool state = 0;
void setup() {
Serial.begin(115200);
TCCR1A = 0;
TCCR1B = 0;
TCCR1B = (1 << WGM12) | (1 << CS11);
TIMSK1 = 0;
TIMSK1 = (1 << OCIE1A) | (1 << OCIE1B);
OCR1A = 20000;
OCR1B = 6000;
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
digitalWrite(7, LOW);
digitalWrite(8, LOW);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
}
ISR(TIMER1_COMPA_vect) {
off();
state = !state;
}
ISR(TIMER1_COMPB_vect) {
if (state == 0) {
highon();
}
else {
lowon();
}
}
void loop() {
}
void off() {
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
digitalWrite(8, LOW);
digitalWrite(7, LOW);
}
void highon() {
digitalWrite(9, LOW);
digitalWrite(10, HIGH);
digitalWrite(8, LOW);
digitalWrite(7, HIGH);
}
void lowon() {
digitalWrite(9, HIGH);
digitalWrite(10, LOW);
digitalWrite(8, HIGH);
digitalWrite(7, LOW);
}
Also really if you want your waveform to be more accurate, consider writing to the port directly (rather than digitalWrite() )