We want an Arduino to do this job. And we want a digital display to see the value of the produced frequency.
Some restrictions we will have to accept:
Which range of frequencies will be possible?
| Prescaler-Code |
| corresponding |
| high value of counter |
| calculation |
frequency in Hertz
|7||1024||249||16.000.000 / 1024 / (249+1) / 2 = 31,25|
|1||1||0||16.000.000 / 1 / (0 + 1) / 1 = 8.000.000|
So you get more than 5 decades by turning your knob.
As you can combine 7 prescaler values and 256 high values (OCR2A register) you get 7 * 256 = 1792 frequencies. But some of them are identical or differ from as little as 0.4 per cent from one another.
As the frequency selector will be a potentiometer connected to an analog input you only can get the input values from 0 to 1023.
If you want that the selectable frequencies will differ at least by 1 per cent from each other, you get 676 frequencies that means you have to store 676 pairs of prescalers and ocr2a-values. We save these values in a *.h file and read these values directly from the flash memory.
A potentiometer (any value between 10 kOhm and 1 MOhm will do) connected to analog input A0 gives values from 0 to 1023 which will be mapped to the range from 1 to 676.
As there will be some noise on the analog input we take a sliding average. The side effect is when you start the controller it takes some time until the selected frequency is produced.
the parameters for prescaler and OCR2A