VERIABLE FREQUENCY 1HZ-500HZ

WANT TO GENERATE VERIABLE FREQUENCY 1HZ-500HZ WHAT SHULD I USE (TIMER ,PMW, TONE) FOR BETTER RESULT IN UNO BOARD

tone() is probably the easiest way to do this with a function that is included by default (assuming you want a 50% duty cycle - that is the pin is ON for the half period and OFF for the other half period)

On your Uno it will work with frequencies between 31Hz and 65535Hz. just make sure you pass the frequency from an unsigned int variable

drawback --> works only on 1 pin at a time. need to call noTone() on the first pin if you want to play a frequency on another pin.

PWM won't give you a frequency where the ON part is as long as the OFF part. you just define the "pulse width", i.e. how long the ON part is and the OFF part will be the rest of the time for a full period. You don't have super precise control of the period and changing the PWM frequency changes the timers and disrupts the normal operation of many functions that rely on time (delay(), millis(), Servo library.

if you go use Timers, then you basically duplicate what tone() does for you :slight_smile:

i want to generate using timer interrupt ,but problem is it uses interrupt and i don,t kown how to use ISR in FREERTOS MY PROJECT NEED TO DISPLY ON LCD SO RTOS IS REQUIRED THERE!!!! WHAT TO DO?

please explain why you need RTOS...

if you need to display on a LCD you clearly don't need a real time OS. LCD are generally slow.

I M USING LCD TO DISPLY CLOCK WHICH IS ADJESTABLE ANYTIME, SO THERE IS NEED OF RTOS , I THINK BUT I M NOT SURE !!!

Please take your caps lock off

no there is no need... please don't use capital letters, this is considered as shouting which is bad... do you really want to shout at me?

of course not ,sorry for that

SANDIE:
WHAT TO DO?

Stop shouting for a start.

There is no need for any operating system at all.

You need to specify what resolution you need the frequency changes to be 10Hz or finer?
How do you want to input a change in frequency?
Do you need a square wave output or will pulsed waveform be enough?
You can simply write to the LCD before you change the frequency.

i need square wave between 1hz-500hz its variable in my programe ,and also disply clock which is too variable in between any time.

How do you get the hour? do you have a RTC?
what type of LCD do you have? basic or with a I2C LCD Backpack ?

see an example of a LCD clock here

SANDIE:
i need square wave between 1hz-500hz its variable in my programe ,and also disply clock which is too variable in between any time.

In what possible way does this answer any of this

Grumpy_Mike:
You need to specify what resolution you need the frequency changes to be 10Hz or finer?
How do you want to input a change in frequency?
Do you need a square wave output or will pulsed waveform be enough?
You can simply write to the LCD before you change the frequency.

now i need to calulate frequency using this formula (1610^6) / (11024) - 1
what i m doing that 16000000x1x1024-1=16383 OCR1A = 16383 i get 1 hz of frequency how to calculate for 10 hz and so on when i m calculating the same 5 digit is coming

Maybe you're always substituting the same numbers.
That's a good way of getting the same answers.

Clock period = 1/16e6

Desired output frequency = 10Hz
Desired output period = 1/10

CPU ticks per output period = output period / clock period = (1/16e6) / (1/10)

= 1,600,000 ticks.

16 bit timer holds up to 65536 in its register. The number you require is too large to fit in the register.

Use the clock prescalar:

Set bits CS12,CS11 and CS10 to 101 in the TCCR1B register for clk/1024

So now each "tick" occurs once every 1024 CPU ticks...

1,600,000 / 1024 = ~ 1562 ticks after the 1024 pre-scalar.

Done this in my head quickly so yeah...check it.

Half it for the "on" and "off" time.

PS: Refer to datasheet chapter 16 "16bit Timer/Counter1 with PWM".

You can set the pre-scalar dependent on the users desired output frequency. Use a pre-scalar for longer period times. You will need to work these out ofc for your system.

thamks let me do as u said