Need help making the code from MS to NS

We are trying to convert the measure of time from milliseconds to nanoseconds. I am unsure how to use the millisecond and time conversion of 62.5 to make it in nanoseconds.

`//pin connected to the LED
const int ledPin = 13;

void setup() {
  // put your setup code here, to run once:
  pinMode(ledPin, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  // Turn the LED on 
  digitalWrite(ledPin, HIGH);
  delay(.2);

  //turn the LED off
  digitalWrite(ledPin, LOW);
  delay (2);
}
`

AVR processor? Running at 16 MHz?

It runs at 16 MHz and yes it is the factory made avr processor

If you really need a 62.5 nanosecond granularity then you will not be able to use the Arduino Core (no digitalWrite, no delay, timer 0 interrupt turned off).

The time conversion from milliseconds to nanoseconds is 1,000,000

The conversion from nanoseconds to clock cycles involves the 62.5

The delay function only takes integral values. You can't use a decimal number.

delayMicroseconds(200);
will do what it looks like you want in that line.

It isn't really clear what you actually want to do. If you're trying to toggle a pin very fast with some nanosecond resolution then use a PWM timer. That's what they're built for.

What type of Arduino are you using?

You might use

  delayMicroseconds(200);

here, but making nanosecond measured pulses will not come from plain literal code like this.

@Delta_G's typing is measured in keystrokes per millisecond, it seems.

a7

wouldnt delayMicroseconds(200) be 0.2 nanoseconds which the board cannot do numerical values that aren't integers I believe. What would be a way around this?

Review your SI prefixes.

200 microseconds is 200000 nanoseconds.

a7

You might need to work on your math before you go too far coding this. 200 microseconds is 200,000 nanoseconds.

That's not what you were told. What we said was that the delay function only takes integers. The delayMicroseconds function also only takes integers. 200 is an integer. There is no decimal on 200.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.