0

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.

  • 1
    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
1

It is unclear exactly what you are trying to do, however the frequency generated by the code would be ~5Hz - corresponding to a period of 200mS

| improve this answer | |
  • Thanks, what is the equation that you applied to come to that answer? Oh, (forehead slap) it is generating a pulse every 200mS so 1000mS (1S) / 200mS = 5Hz. So it would actually be ~5Hz (not kHZ), right? Thanks for answering. If you change it to Hz I will mark it as the answer. You helped me get to the right point. I had been thinking something else. Thanks. – raddevus Oct 31 '18 at 1:06
1

The dependency on the clock speed is hidden in the implementation of the delay() function. It works with 'human readable' milliseconds.

Hertz is count of repeating in one second. One second has 1000 ms. So with 200 ms delay, 5 repeating happen in a second. Then the frequency is 5 Hz.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.