Hey guys,
i want to generate two square waves with variable frequencies (50% duty cycle and same amplitude). The problems is when i generate two square waves they need to have the same frequency, if not the signal does not match the given frequency. I dont understand this because the two output pins have different timers. I show you a simple code where i test this:
void setup() {
// initialize digital pin 13 as an output.
pinMode(11, OUTPUT);
pinMode(2, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(11, HIGH); // turn the LED on (HIGH is the voltage level)
delayMicroseconds(125); // wait for a second
digitalWrite(11, LOW); // turn the LED off by making the voltage LOW
delayMicroseconds(125); // wait for a second
digitalWrite(2, HIGH); // turn the LED on (HIGH is the voltage level)
delayMicroseconds(125); // wait for a second
digitalWrite(2, LOW); // turn the LED off by making the voltage LOW
delayMicroseconds(125); // wait for a second
}
It is just a simple Blink Code, so i think the idea with delayMicroseconds is not that good. I get a hint to use ISR but dont know how to handle it. So my target is to get the variable frequency by a serial signal. And this should set the frequencies of the square waves. I need frequencies of about 400 Hz to 2600 Hz, so i think this should be possible with this board with no problems, i hope so. So does anybody have an idea which could help me? The following is in German, maybe there is someone who would like to write in german. Thank you for taking time.
best regards
Hallo Jungs,
also ich möchte gerne zwei variable Rechtecksignale mit verschiedenen Frequenzen generieren (der Tastgrad sollte 50% sein und die amplituden sollten gleich sein). Das Problem jedoch ist, dass wenn ich zwei Rechtecksignale generiere und sie nicht die selbe Frequenz haben dann stimmen die Frequenzen nicht. Dieses verstehe ich nicht da ja die beiden Outputs verschiedene Timer haben sollten sie doch unabhängig sein. Der nachfolgende Code stellt den Fall dar mit dem ich es getestet habe.
void setup() {
// initialize digital pin 13 as an output.
pinMode(11, OUTPUT);
pinMode(2, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(11, HIGH); // turn the LED on (HIGH is the voltage level)
delayMicroseconds(125); // wait for a second
digitalWrite(11, LOW); // turn the LED off by making the voltage LOW
delayMicroseconds(125); // wait for a second
digitalWrite(2, HIGH); // turn the LED on (HIGH is the voltage level)
delayMicroseconds(125); // wait for a second
digitalWrite(2, LOW); // turn the LED off by making the voltage LOW
delayMicroseconds(125); // wait for a second
}
Das ist ein simpler Blink Code den ich bisschen verändert habe. Ich habe einen Tipp bekommen ISR zu nutzen jedoch weiss ich damit nicht umzugehen. Also mein Ziel ist es die variablen Frequenzen über eine serielle Leitung dem Board zuzuspielen und die Frequenzen der Rechtecksignale damit zu stellen. I benötige Frequenzen von ca. 400 Hz bis 2600 Hz, dass denke ich sollte möglich sein mit dem Board. Ich hoffe jemand hat eine gute Idee oder Vorgabe an die ich mich halten kann. Vielen Dank und Grüße im Voraus.