TimerOne.h Library Problem with Arduino Nano

I'm new arduino user. I started learning arduino a month ago, to make some project about PWM control. I want to make 100kHz PWM Signal with Duty Cycle can be vary using potentiometer.

I made that signal thanks the people on this thread: 100 kHz pwm - Using Arduino / Programming Questions - Arduino Forum

Now i got a problem after adding the potentiometer setting part on my program.

This is the error message:


**Using board 'nano' from platform in folder: C:\Users\Ahmad Alfikri\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.5**
**Using core 'arduino' from platform in folder: C:\Users\Ahmad Alfikri\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.5**
**Detecting libraries used...**
**"C:\\Users\\Ahmad Alfikri\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR "-IC:\\Users\\Ahmad Alfikri\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.5\\cores\\arduino" "-IC:\\Users\\Ahmad Alfikri\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.5\\variants\\eightanaloginputs" "C:\\Users\\Ahmad Alfikri\\AppData\\Local\\Temp\\arduino-sketch-D734AC4F84FABAB6116AAB19FF14E0A7\\sketch\\pwm100k.ino.cpp" -o nul**
**Alternatives for TimerOne.h: [TimerOne@1.1]**
**ResolveLibrary(TimerOne.h)**
**  -> candidates: [TimerOne@1.1]**
**"C:\\Users\\Ahmad Alfikri\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR "-IC:\\Users\\Ahmad Alfikri\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.5\\cores\\arduino" "-IC:\\Users\\Ahmad Alfikri\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.5\\variants\\eightanaloginputs" "-IC:\\Users\\Ahmad Alfikri\\Documents\\Arduino\\libraries\\TimerOne" "C:\\Users\\Ahmad Alfikri\\AppData\\Local\\Temp\\arduino-sketch-D734AC4F84FABAB6116AAB19FF14E0A7\\sketch\\pwm100k.ino.cpp" -o nul**
**Using cached library dependencies for file: C:\Users\Ahmad Alfikri\Documents\Arduino\libraries\TimerOne\TimerOne.cpp**
**Generating function prototypes...**
**"C:\\Users\\Ahmad Alfikri\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR "-IC:\\Users\\Ahmad Alfikri\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.5\\cores\\arduino" "-IC:\\Users\\Ahmad Alfikri\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.5\\variants\\eightanaloginputs" "-IC:\\Users\\Ahmad Alfikri\\Documents\\Arduino\\libraries\\TimerOne" "C:\\Users\\Ahmad Alfikri\\AppData\\Local\\Temp\\arduino-sketch-D734AC4F84FABAB6116AAB19FF14E0A7\\sketch\\pwm100k.ino.cpp" -o "C:\\Users\\Ahmad Alfikri\\AppData\\Local\\Temp\\arduino-sketch-D734AC4F84FABAB6116AAB19FF14E0A7\\preproc\\ctags_target_for_gcc_minus_e.cpp"**
**"C:\\Users\\Ahmad Alfikri\\AppData\\Local\\Arduino15\\packages\\builtin\\tools\\ctags\\5.8-arduino11/ctags" -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives "C:\\Users\\Ahmad Alfikri\\AppData\\Local\\Temp\\arduino-sketch-D734AC4F84FABAB6116AAB19FF14E0A7\\preproc\\ctags_target_for_gcc_minus_e.cpp"**
**Compiling sketch...**
**"C:\\Users\\Ahmad Alfikri\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR "-IC:\\Users\\Ahmad Alfikri\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.5\\cores\\arduino" "-IC:\\Users\\Ahmad Alfikri\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.5\\variants\\eightanaloginputs" "-IC:\\Users\\Ahmad Alfikri\\Documents\\Arduino\\libraries\\TimerOne" "C:\\Users\\Ahmad Alfikri\\AppData\\Local\\Temp\\arduino-sketch-D734AC4F84FABAB6116AAB19FF14E0A7\\sketch\\pwm100k.ino.cpp" -o "C:\\Users\\Ahmad Alfikri\\AppData\\Local\\Temp\\arduino-sketch-D734AC4F84FABAB6116AAB19FF14E0A7\\sketch\\pwm100k.ino.cpp.o"**
**Compiling libraries...**
**Compiling library "TimerOne"**
**Using previously compiled file: C:\Users\Ahmad Alfikri\AppData\Local\Temp\arduino-sketch-D734AC4F84FABAB6116AAB19FF14E0A7\libraries\TimerOne\TimerOne.cpp.o**
**Compiling core...**
**Using precompiled core: C:\Users\Ahmad Alfikri\AppData\Local\Temp\arduino-core-cache\core_arduino_avr_nano_cpu_atmega328old_26a0fa43298f98f8fe38062a57de744c.a**
**Linking everything together...**
**"C:\\Users\\Ahmad Alfikri\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-gcc" -w -Os -g -flto -fuse-linker-plugin -Wl,--gc-sections -mmcu=atmega328p -o "C:\\Users\\Ahmad Alfikri\\AppData\\Local\\Temp\\arduino-sketch-D734AC4F84FABAB6116AAB19FF14E0A7/pwm100k.ino.elf" "C:\\Users\\Ahmad Alfikri\\AppData\\Local\\Temp\\arduino-sketch-D734AC4F84FABAB6116AAB19FF14E0A7\\sketch\\pwm100k.ino.cpp.o" "C:\\Users\\Ahmad Alfikri\\AppData\\Local\\Temp\\arduino-sketch-D734AC4F84FABAB6116AAB19FF14E0A7\\libraries\\TimerOne\\TimerOne.cpp.o" "C:\\Users\\Ahmad Alfikri\\AppData\\Local\\Temp\\arduino-sketch-D734AC4F84FABAB6116AAB19FF14E0A7/..\\arduino-core-cache\\core_arduino_avr_nano_cpu_atmega328old_26a0fa43298f98f8fe38062a57de744c.a" "-LC:\\Users\\Ahmad Alfikri\\AppData\\Local\\Temp\\arduino-sketch-D734AC4F84FABAB6116AAB19FF14E0A7" -lm**
**"C:\\Users\\Ahmad Alfikri\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-objcopy" -O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 "C:\\Users\\Ahmad Alfikri\\AppData\\Local\\Temp\\arduino-sketch-D734AC4F84FABAB6116AAB19FF14E0A7/pwm100k.ino.elf" "C:\\Users\\Ahmad Alfikri\\AppData\\Local\\Temp\\arduino-sketch-D734AC4F84FABAB6116AAB19FF14E0A7/pwm100k.ino.eep"**
**"C:\\Users\\Ahmad Alfikri\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-objcopy" -O ihex -R .eeprom "C:\\Users\\Ahmad Alfikri\\AppData\\Local\\Temp\\arduino-sketch-D734AC4F84FABAB6116AAB19FF14E0A7/pwm100k.ino.elf" "C:\\Users\\Ahmad Alfikri\\AppData\\Local\\Temp\\arduino-sketch-D734AC4F84FABAB6116AAB19FF14E0A7/pwm100k.ino.hex"**

**Using library TimerOne at version 1.1 in folder: C:\Users\Ahmad Alfikri\Documents\Arduino\libraries\TimerOne **
**"C:\\Users\\Ahmad Alfikri\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-size" -A "C:\\Users\\Ahmad Alfikri\\AppData\\Local\\Temp\\arduino-sketch-D734AC4F84FABAB6116AAB19FF14E0A7/pwm100k.ino.elf"**
**Sketch uses 2160 bytes (7%) of program storage space. Maximum is 30720 bytes.**
**Global variables use 201 bytes (9%) of dynamic memory, leaving 1847 bytes for local variables. Maximum is 2048 bytes.**
**"C:\Users\Ahmad Alfikri\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/bin/avrdude" "-CC:\Users\Ahmad Alfikri\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/etc/avrdude.conf" -v -V -patmega328p -carduino "-PCOM3" -b57600 -D "-Uflash:w:C:\Users\Ahmad Alfikri\AppData\Local\Temp\arduino-sketch-D734AC4F84FABAB6116AAB19FF14E0A7/pwm100k.ino.hex:i"**

**avrdude: Version 6.3-20190619**
**         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/**
**         Copyright (c) 2007-2014 Joerg Wunsch**

**     Failed uploading: uploading error: exit status 1    System wide configuration file is "C:\Users\Ahmad Alfikri\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/etc/avrdude.conf"**

**         Using Port                    : COM3**
**         Using Programmer              : arduino**
**         Overriding Baud Rate          : 57600**
**avrdude: ser_open(): can't open device "\\.\COM3": Access is denied.**

**avrdude done.  Thank you.**

I thougt this was a port problem, but changing the port settings didn't solve the problem.
Reinstall the port driver also didn't solve the problem. Could anyone give me the solution? If this was a program error, could you tell me which part that made the error?

1. Post your sketch and tell the Arduino type.
2. Check that you have connected potentiometer as per Fig-1 or similar to vary duty cycle.
pwmdutyCycle
Figure-1:

3. Check that your sketch contains the following line in the loop() function:

Timer1.pwm(9, analogRead(A0));

Are you sure your board is on COM3?

Which ports do you see in the device manager with the board disconnected and what do you see when the board is connected?

  1. Arduino Nano. My Sketch:
#include <TimerOne.h>
#define pot A0

int value;
void setup()
{
  pinMode(10,OUTPUT);
  Serial.begin(9600);
  pinMode(pot, INPUT);
  Timer1.initialize(10); // Frequency, 10us = 100khz 
}

void loop()
{
  value = analogRead(pot);
  value = map(value,0,1023,0,1023);
  Timer1.pwm(10,value);
  Serial.print("value :");
  Serial.println(value);
}
  1. I've connected the potentiometer on that pin

  2. Nope, where should i put that line?

When the board is connected: COM3
When the board is disconnected: No Port Option

The first time i installled the port driver, it shows that the nano connected via port COM3

Then I guess there is some other software running that uses this port. You could try to close some suspicious applications (like 3d printer software) or reboot your computer.

1. Your sketch looks good and yet delete the map() function.

#include <TimerOne.h>
#define pot A0

int value;
void setup()
{
  pinMode(10,OUTPUT);
  Serial.begin(9600);
  pinMode(pot, INPUT);
  Timer1.initialize(10); // Frequency, 10us = 100khz 
}

void loop()
{
  value = analogRead(pot);
  //value = map(value,0,1023,0,1023);
  Timer1.pwm(10, value);
  Serial.print("value :");
  Serial.println(value);
}

2. Try with:
IDE ----> Tools ----> Processor ----> ATmega 328P (Old Bootloader)

3. To check the functioning of the PWM, set frequency at 1 Hz, connect a LED1 at DPin-10 similar to Fig-1 of Post #2 with value (duty cycle) = 512. The LED1 should blink.

  1. Deleting the map() function didn't solve the problem.

  2. I tried this also, didn't work.

  3. How do i set the freq to 1 Hz? In which line of the program?

  4. Should i put this line on my program?

Timer1.pwm(9, analogRead(A0));

Check if you can upload the blink program in your UNO from the Examples of the IDE and observe that the L (built-in LED) blinks.

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