Hey guys, I’m new here so sorry if my question is silly.
I’m trying to create a simple function generator with an Arduino Uno.
I’ve trying to play with two codes:
void setup()
{
pinMode(8, OUTPUT);
}
void loop()
{
// A total delay of 4 ms = 1/0.004 = 250 Hz…
digitalWrite(8, HIGH);
delayMicroseconds(2000);
digitalWrite(8, LOW);
delayMicroseconds(2000);
}
It’s a simple code, so I could understand how it works. I tried to create an RC filter in order to obtain a pure wave (instead of square wave).
I got a triangular wave and couldn’t get frequency values greater than 500Hz (delay~1000ms)
This is the second code:
unsigned long t0;
void setup() {
pinMode(9, OUTPUT);
t0 = millis();
TCCR1B = 0x01;
}
void loop() {
analogWrite(9, (int) (255.0 * 0.5 *(1.0 + sin( (float) ((millis()-t0) % 1000) * 2.0 * 3.14 * 5.0 / 1000))));
}
In this case I could create the sin wave but I can’t either change it or measure it. I used the same RC filter.
My main objective with that is to get a sin wave which I can choose between 20KHz and 50KHz. I’m using ISIS Proteus as well, what allow me to create the filters and analyze the frequency.
Does anyone have some knowledge to help me with that?
Thanks.