Author Topic: About Arduino Uno's Xtal Osc  (Read 650 times)

0 Members and 1 Guest are viewing this topic.

Offline dhumx

  • Contributor
  • Posts: 5
  • Country: ph
About Arduino Uno's Xtal Osc
« 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
 

Offline agehall

  • Regular Contributor
  • *
  • Posts: 249
  • Country: se
Re: About Arduino Uno's Xtal Osc
« Reply #1 on: March 25, 2019, 06:00:04 pm »
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.
 

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 8052
Re: About Arduino Uno's Xtal Osc
« Reply #2 on: March 25, 2019, 08:00:55 pm »
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.
« Last Edit: March 25, 2019, 08:02:36 pm by Ian.M »
 

Offline PCB.Wiz

  • Frequent Contributor
  • **
  • Posts: 379
  • Country: au
Re: About Arduino Uno's Xtal Osc
« Reply #3 on: March 25, 2019, 09:32:10 pm »
..I want to have a clock of at least 1 Hz. ..
I want to produce a variable clock frequency

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

Offline luxetveritas

  • Contributor
  • Posts: 7
  • Country: us
Re: About Arduino Uno's Xtal Osc
« Reply #4 on: March 31, 2019, 03:40:58 am »
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

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.
 

Online Nusa

  • Super Contributor
  • ***
  • Posts: 1593
  • Country: us
Re: About Arduino Uno's Xtal Osc
« Reply #5 on: March 31, 2019, 05:50:48 am »
^ If your frequency needs are modest, the tone() library should suffice.
https://www.arduino.cc/reference/en/language/functions/advanced-io/tone/

If your needs are more extreme, I suggest the Timer1 library:
https://github.com/PaulStoffregen/TimerOne

There are other ways to slay the beast, none of them terribly hard, but the fact you asked the question at all indicates you are a beginner, at least on the software side of things.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf