Maker Pro
Maker Pro

Cheapest way 2 generate 22Khz clock?

R

Rich Grise

---
The problem with that approach is that the clock divider needs to function
in real time, so even if there's a free-running internal peripheral
counter in the chip which can generate interrupts, an ISR needs to be
written which will generate the divide-by and output the 22kHz signal. If
there are other time-critical events which the µC is supposed to take
care of, then it can easily become a nightmare to try to keep everybody
happy. In either case, it's a little more involved than just writing "one
more little loop". ---

Well, I'm actually rather an adept programmer, even if it doesn't show all
the time. :) I've already answered Mark's followup, and asked him to post
the code. It's written in PicBasic, for heaven's sakes - how time-critical
can it be?
---
_And_ the temperature, _and_ the supply. Might as well get a 7555 if you
want to go that route and get some insensitivity to supply voltage and
ambient temperature variations.
---

Very good point. I was a little on the glib side there. :)

Thanks!
Rich
 
J

John Fields

It's written in PicBasic, for heaven's sakes - how time-critical
can it be?
 
F

Frank Bemelman

Rich Grise said:
Well, I'm actually rather an adept programmer, even if it doesn't show all
the time. :) I've already answered Mark's followup, and asked him to post
the code. It's written in PicBasic, for heaven's sakes - how time-critical
can it be?

The question is, how critical is that 22KHz. If there are already
other interrupts, the new 22KHz may show some jitter. The PIC has
a rather simple interrupt system, new interrupts will be pending
if another one is in service.

But it is worth looking into.

[snip]
 
S

Spehro Pefhany

The question is, how critical is that 22KHz. If there are already
other interrupts, the new 22KHz may show some jitter.

That's why I suggested using a CCP module. As long as you can service
the interrupt (updating the compare register) before the end of the
next half-cycle there is no jitter (figuratively speaking). The
accuracy is limited by the clock frequency accuracy and the resolution
of the counter (4 oscillator clocks).
The PIC has
a rather simple interrupt system, new interrupts will be pending
if another one is in service.

You can nest interrupts on all PICs that have interrupts.


Best regards,
Spehro Pefhany
 
R

Rich Grise

That's why I suggested using a CCP module. As long as you can service the
interrupt (updating the compare register) before the end of the next
half-cycle there is no jitter (figuratively speaking). The accuracy is
limited by the clock frequency accuracy and the resolution of the counter
(4 oscillator clocks).


You can nest interrupts on all PICs that have interrupts.

I've just been looking at the 16F5X data sheet, and Eek! It seems it
doesn't even have interrupts at all, ergo no timer interrupt. Whaddaya
gotta poll the timer?

I might end up eating my words about "generate the clock in the existing
pic" - but I still want to see Mark's code.

Thanks!
Rich
 
F

Frank Bemelman

Spehro Pefhany said:
That's why I suggested using a CCP module. As long as you can service
the interrupt (updating the compare register) before the end of the
next half-cycle there is no jitter (figuratively speaking). The
accuracy is limited by the clock frequency accuracy and the resolution
of the counter (4 oscillator clocks).


You can nest interrupts on all PICs that have interrupts.

Good point. I should have added 'default' or something. Rich was
so kind to look up the 16F57 datasheet, seems a rather crippled
PIC with no interrupts to worry about at all ;)
 
T

Tony Williams

Mark said:
OK so a PIC seems to rear its ugly head once again (there is
already one in another part of this design) which one should I
use and is there any pre-written code I can use, as my
programming skills are in the beginers stage.

There is an easy crash-bang solution that requires
zero programming skills.

Choose any PIC that will work with a 4MHz 3-legged
resonator. A 4MHz PIC will do an instr every 1uS.
21739Hz is a period of 46uS. So have a simple
programme loop that is 46 instructions long.

Instruction#01. Set the output pin to a 1.
NOP
NOP
 
S

Spehro Pefhany

I've just been looking at the 16F5X data sheet, and Eek! It seems it
doesn't even have interrupts at all, ergo no timer interrupt. Whaddaya
gotta poll the timer?

Hey, you're lucky to have a couple of levels of subroutines! You could
also write isochronous code that toggles the pin every so many
instructions. ;-) But you're not going to do that in a HLL. The 16x5x
is still used in huge volume because it's cheap, and if you don't need
to do very complex it's usable.
I might end up eating my words about "generate the clock in the existing
pic" - but I still want to see Mark's code.

Thanks!
Rich


Best regards,
Spehro Pefhany
 
F

Fred Bartoli

Tony Williams said:
There is an easy crash-bang solution that requires
zero programming skills.

Choose any PIC that will work with a 4MHz 3-legged
resonator. A 4MHz PIC will do an instr every 1uS.
21739Hz is a period of 46uS. So have a simple
programme loop that is 46 instructions long.

Instruction#01. Set the output pin to a 1.
NOP
NOP
.
.
Instruction#24. Set the output pin to a 0.
NOP
NOP
.
.
Instruction#45. Jump
Instruction#46. To Instruction#01.

When you have the simple programme going you can think
about using up those NOPs to make the PIC do other
things as well.

LOL.
Makes me wonder. Add a couple ADD or INC instrructions and you'll have a NOP
DDS (neat oddly programmable DDS).
 
R

Rich Grise

Hey, you're lucky to have a couple of levels of subroutines! You could
also write isochronous code that toggles the pin every so many
instructions. ;-)

Believe it or not, one of the first programs I wrote for my first PC, a
Scelbi 8H, 8008, 256 Bytes RAM expanded to 1K, used that. I wasn't
satisfied with my musical tone player timing loops, because you had to
figure out frequency and duration and give it two parameters for each
note. This was a PITA, so I wrote two concurrent loops, one for the period
and one for the duration of the note. Or maybe "interleaved" would be a
better term.
But you're not going to do that in a HLL. The 16x5x is
still used in huge volume because it's cheap, and if you don't need to do
very complex it's usable.

After looking at that spec, I'd _really_ like to see what a PicBasic
program looks like!

Thanks!
Rich
 
T

Tony Williams

LOL. Makes me wonder. Add a couple ADD or INC instrructions and
you'll have a NOP DDS (neat oddly programmable DDS).

:)

Don't laugh.... It's an easy quick and dirty way of getting
synchronised clocks and/or multiple phases.
 
Top