Delay microseconds wit Atmega328P barebones working at 1MHz 1.8V

Hi, guys. Rencently, I want to use Atmega328p barebones @1MHz powered by 1.8V to control MOSFET for switching function. When a interrupt signal comes, a digital pin of 328p outputs a high voltage for about 40us. I have tried the function delayMicrosecond(), but the result measured through oscilloscope was not right. The deviation is big. Then I also tried _delay_us() function in util/delay.h. The tested result was not accurate as well. It seems the measured minimum delay time cannot be less than 50us according to the wave on oscilloscope.

I guess it is because of the 1MHz frequency of MCU. However, I need it working low voltage for ultra-low power consumption.

Anyone can help me, thanks in advance.

Nick

Post a full example. _delay_us() should allow 40us delays even at 1MHz, but you can eat up time depending on other factors...

westfw:
Post a full example. _delay_us() should allow 40us delays even at 1MHz, but you can eat up time depending on other factors...

Thanks for your reply. I just used the simplest code to check the delay time. Is _delay_us() work well with 1MHz?

#include <util/delay.h>

int outPin = 8;               // digital pin 8

void setup() {
  pinMode(outPin, OUTPUT);    // sets the digital pin as output
}

void loop() {
  digitalWrite(outPin, HIGH); // sets the pin on
  _delay_us(40);
  digitalWrite(outPin, LOW);  // sets the pin off
  _delay_us(40);
}

digitalwrite is slow.. try bitset / bitclear

At 1Mhz the arduino is taking 1uS per instruction at best, so you will get a lot of timing deviation fron the background interrupts.