Computing > Embedded Computing

About Arduino Uno's Xtal Osc

(1/2) > >>

dhumx:
Hi all, is there any way that I can output a clock in arduino uno? I want to have a clock of at least 1 Hz. I know about PWM of the arduino but to my best knowledge, the PWM output of arduino has fixed frequency. I want to produce a variable clock frequency

agehall:
PWM is not what you are looking for. The hint is in the name - Pulse WIDTH Modulation.

You can get a lot more than 1Hz from an Arduino by simply toggling the pins in your code. Even with the digitalWrite() function (which is horrible in terms of performance) you should get a lot more than single digit hertz.

Ian.M:
Although the PWM functionality exposed by the Arduino analogWrite() function is fixed frequency, the underlying hardware PWM is not.   e.g. on ATmega328P based Arduinos, if you take direct control of the Timer 1 registers, you can set up a PWM with a frequency ranging from 0.12Hz to over 1MHz.  See section 20. TC1 - 16-bit Timer/Counter1 with PWM, of the ATmega328P's datasheet.   

Ardunos based on other MCUs generally have fairly similar capabilities although the limits of their hardware PWM frequency range will be different - consult the specific MCU's datasheet for details.

PCB.Wiz:

--- Quote from: dhumx on March 25, 2019, 05:44:53 pm ---..I want to have a clock of at least 1 Hz. ..
I want to produce a variable clock frequency

--- End quote ---

What frequency range do you expect, and what precision do you need ? (step size, in  Hz or %f )

luxetveritas:

--- Quote from: dhumx on March 25, 2019, 05:44:53 pm ---Hi all, is there any way that I can output a clock in arduino uno? I want to have a clock of at least 1 Hz. I know about PWM of the arduino but to my best knowledge, the PWM output of arduino has fixed frequency. I want to produce a variable clock frequency

--- End quote ---

Maybe use tone(pin, frequency [, duration])?  It outputs a square wave with 50% duty cycle.  Frequency is an unsighed int so can go to 65535Hz.  Use noTone(pin) to stop.

Navigation

[0] Message Index

[#] Next page

There was an error while thanking
Thanking...
Go to full version