High Resolution, Low Freq Generator?

vk3jme

New Member
Hi all,

I first started playing with PICAXE about 9 months ago, but I discovered that PICAXE wouldn't provide a good solution to my project, so the project got shelved and I haven't played with it since.
Anyhow, I'm trying to create a CTCSS encoder for one of my old Ham Radios.
The local repeater has had Tone access installed to to allow me to key it.

A similar subject has been raised before, but never got resolved.
I know that I could probably achieve the same out come with a 555 timer, but I thought I might just pull the PICAXEs out and have another go.
This time using a 08-M

CTCSS tones are sub-audible.
The tone I am after is 123.0Hz, I thought about PWM, but PWMOUT won't come down that far.
So I looked at the SOUND command
Code:
main:
sound 1,(##,255)
pause 1000
goto main
Where ## is the following, the measured frequencies were:
27 = 121.9 Hz
28 = 121.9 Hz
29 = 125.0 Hz
30 = 125.0 Hz

Close, but not close enough.
Next thought was just to toggle the output manually:
Code:
main:
high 1
pause #
low 1
pause #
goto main
Where # is the following, the measured frequencies were:
3 = 136.9 Hz
4 = 106.3 Hz
5 = 87.7 Hz

I tried increasing the CPU speed with SETFREQ M8
I then got:
7 = 128.2 Hz
8 = 116.2 Hz
9 = 102.0 Hz

Has anyone got any ideas how I can get closer to the mark of 123Hz?

Thanks,

Jamie
 

BeanieBots

Moderator
Without giving any serious thought to the issue, my first consideration would be the use of a divider stage after a PWMout pin.
 

Dippy

Moderator
It's a PWM day today obviously.

pwmout <pin> , 253, 508 = 3936 Hz @ 4MHz xtal.


Set T2CON register (12h) bit 1 to 1 to give prescale 16.
Gives 246 Hz. (~244 is the lowest PWM with prescale @ 4MHz xtal)

External divide by 2 and bingo, 123Hz.
(Sounds so easy when just typing and not doing).

I'm not sure whether pokey timer interrupts are practical.
Or even a sound which is a convenient multiple.

A 555 would be easier and more finely trimmable:)
 

womai

Senior Member
You could use pulsout to a dummy output pin (that isn't otherwise used) for much finer delay resolution than pause allows - 10us at 4 MHz, 5 us at 8 MHz.

Wolfgang
 

vk3jme

New Member
You could use pulsout to a dummy output pin (that isn't otherwise used) for much finer delay resolution than pause allows - 10us at 4 MHz, 5 us at 8 MHz.

Wolfgang
Someone Buy Wolfgang a beer!
You are a champion!

I originally dismissed your idea when I saw the pulsout command. I had already tried that and said that that isn't the output signal that I want.
I didn't consider using that as a pause....

Using the following code:
Code:
SETFREQ M8
main:
high 1
pulsout 4,###
low 1
pulsout 4,###
goto main
If ### is the following variable, the frequency follows:
01 = 1240KHz
02 = 1190KHz
05 = 1160KHz
10 = 1080KHz
30 = 862.0Hz
75 = 625.0Hz

150 = 423.7Hz
300 = 256.4Hz
450 = 185.1Hz
600 = 144.9Hz
699 = 126.5Hz
695 = 126.5Hz
690 = 128.2Hz
680 = 129.8Hz
650 = 135.1Hz
700 = 126.5Hz
710 = 125.0Hz
711 = 125.0Hz
714 = 125.0Hz
715 = 125.0Hz
716 = 123.4Hz
717 = 123.4Hz
718 = 123.4Hz
719 = 123.4Hz
720 = 123.4Hz
721 = 123.4Hz
722 = 121.9Hz
723 = 121.9Hz
725 = 121.9Hz
727 = 121.9Hz
728 = 121.9Hz
730 = 121.9Hz

123.4Hz what is going to argue 0.4Hz off freq?
Mind you I am using a Velleman HPS-40 Handheld LCD CRO to read the frequency, so there may actually be a difference between 716 and 721 in actual frequency!

Please allow me to say the Picaxe 08M is the new age 555 Timer!
It can also be a Low Freq PLL if one desires!
I'm stoked.
Any thoughts on how I can generate 1750Hz and I am home and hosed!

Thankyou,

Jamie
 

hippy

Ex-Staff (retired)
123.4Hz what is going to argue 0.4Hz off freq?
Mind you I am using a Velleman HPS-40 Handheld LCD CRO to read the frequency, so there may actually be a difference between 716 and 721 in actual frequency!
A god rule of thumb would be that the most optimal 123Hz is halfway through the 123.4's, ie, 718.

You can also experiment with adding redundant instructions ( b0=b0, b0=b0+0 ) etc as that will shift timing around slightly but it's a lot of trial and error messing about.

Any thoughts on how I can generate 1750Hz and I am home and hosed!
Howzabout ...

Code:
SetFreq M8
Do
  PulsOut 1, AAA
  pulsOut 4, BBB
Loop
I guess 95 for AAA, with BBB ~= AAA-20, so 75 for BBB, but I may be well out. If you have a scope things will be easier.

Perhaps even better if the PICAXE is dedicated to just producing the tone would be to ...

Code:
SetFreq M8
Do
  PulsOut 1, AAA
  pulsOut 4, AAA
  :
  PulsOut 1, AAA
  pulsOut 4, AAA
  PulsOut 1, AAA
  pulsOut 4, BBB
Loop
Bear in mind that an 08M's internal oscillator can drift with temperature ( and nominal frequency will often be different for each chip ). For ideal timing use a 28X1 with an external crystal, but that may be overkill. See how well you can do with an 08M before concluding you definitely need a 28X1.

I know the 08M can be used with a 32kHz watch crystal to generate an internal timebase. I haven't checked the datasheet but that may be usable to give a fairly accurate count/ trigger which can then be used to produce almost perfect CTSS frequencies.
 

womai

Senior Member
To generate higher frequencies, you could modify your code as follows:

Use a pulsout on your true output pin to generate the high portion of your signal. Use a pulsout on the dummy pin to generate the necessary delay for the low portion. The true output pin will remain low during that time. That reduces the total number of commands and thus makes for faster loop execution = higher maximum frequency.

Code:
SETFREQ M8
low 1

main:
pulsout 1,### ' pin 1 is is high for given time
pulsout 4,### ' pin 1 remains low during that time
goto main
 
Last edited:
Top