I am working on an Arduino Leonardo and I am trying to implement a signalgenerator.
First I want to do a simple rectangular signal.
My first try was to simply use digitalWrite() and set the Output to high, wait some time, set it to low and wait the same time through delay().
I noticed that the digitalWrite() function is quite slow and that delay() is not precise enough. So I am using now to set the Output and reset it a true c command and instead of delay() I am using delayMicroseconds().
It is not working so well thats why I am here.
PORTC |= _BV(PC6);
PORTC &= ~_BV(PC6);
This simple programm should turn on the Output PC6 wait 300us turn it off and wait again, and repeat.
I connected this to an oscilloscope and I am posting the picture now.
As you can hopefully see in the attached picture, the high and low time should be exactly the same. but the high time is something around 400us and the low time around 200us.
I googled a lot and I have no freaking idea whats happening, maybe some of you guys had the same issue.
thanks a lot, cheers