# How can I calculate approximate cycles per second from pulsed pin on Arduino MKR Zero?

The relevant tech specs for a MKR Zero are: 32.768 kHz (RTC*), 48 MHz

*Real-Time Clock

What I'm curious about is how I might do an approximate calculation of cycles per second from operations.

I'm running the following (extremely simplified) code :

``````int pin3 = 3;
void setup() {
//set digital pin pin3 as output

pinMode(pin3,OUTPUT);
}

void loop(){
digitalWrite(pin3,HIGH);//set pin pin3 to +5V
delay(100);//wait 100ms
digitalWrite(pin3,LOW);//set pin pin3 to 0V
delay(100);//wait 100ms
}
``````

Now I'm curious how many cycles per second (approximately) that might account for.

The Equation?

What would the equation be to calculate that?

Not Processor Op Codes

Is this even possible to approximate? I understand it will be difficult because those lines of code do not equal the actual op codes and don't exactly break down to specific cpu cycles or whatever.

Would it be something like:

``````48,000,000 (48MHz) / 200 (millisecond pause) = 240KHz?
``````

Or would I use the real-time clock speed?

``````32768 / 200 = @163Hz
``````

Or something completely different? I'm trying to better understand how I might create a very simple frequency generator and I know that depending upon the chip speed the code will vary.

• Do you know the library for the internal rtc of a arduino mkr zero? arduino.cc/en/Reference/RTC You could increment a counter in the loop and measure it against the real time. For example during an hour, then you can calculate the actual cycles per second. It might be 4.999 Hz per second. You can also use millis to set the output exactly to a certain number of cycles per second. Perhaps even the tone function can be used. – Jot Oct 31 '18 at 1:56