View previous topic :: View next topic |
Author |
Message |
vsmguy
Joined: 13 Jan 2007 Posts: 91
|
Synchronize two frequencies - main signal from the PWM Pin |
Posted: Thu Jun 17, 2010 12:35 pm |
|
|
Consider any 16F/18F series PIC that has hardware PWM.
I would use the PWM Pin to generate a 19Khz pilot signal.
Synchronized with the edges of this signal, I want to turn two pins on port B or C ( digital ports ) on and off, alternately, at 38Khz.
Any suggestions to do this elegantly using only the PIC and no external logic? |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
Sync'd PWMs |
Posted: Sat Jun 19, 2010 10:00 am |
|
|
I'm not clear as to what it is that you actually want.
Is the pilot signal 50% duty?
What is the required relationship between the 19kHz signal and the two signals on the output pins etc.?
If you want to do something at 38kHz, it's usual to start from a higher frequency (say 76kHz in your case).
Mike Walne |
|
|
bkamen
Joined: 07 Jan 2004 Posts: 1615 Location: Central Illinois, USA
|
Re: Synchronize two frequencies - main signal from the PWM P |
Posted: Sat Jun 19, 2010 10:45 am |
|
|
vsmguy wrote: | Consider any 16F/18F series PIC that has hardware PWM.
I would use the PWM Pin to generate a 19Khz pilot signal.
Synchronized with the edges of this signal, I want to turn two pins on port B or C ( digital ports ) on and off, alternately, at 38Khz.
Any suggestions to do this elegantly using only the PIC and no external logic? |
Sounds very "FM Stereo-esque"
Remember the PWM model can generate interrupts. So the port change can exist there.
But also keep in mind, that this is a "single core" microcontroller - so the port changes will be sequential after another. Thus a delay of X number of instructions times the single instruction execution time.
If they need to be near simultaneous, you could still operate in this mode, but gate the PWM and your port pins through an external 74 series latched Flip-Flop or buffer. Use the PWM as your latch signal.
Since the PWM will change state, than IRQ and then your port changes will occur, the updates will happen after the Port B/C changes were made.
But they'll be near simultaneous (even gates and buffers have a delay).
Keep your IRQ routine *short*. Consider using the global/FAST option (no context saves) -- which saves on IRQ handling.
Read up on this so you understand going in.
Cheers,
-Ben _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
|
vsmguy
Joined: 13 Jan 2007 Posts: 91
|
|
Posted: Sat Jun 19, 2010 11:15 am |
|
|
bkamen,
you got it :-D
What I was thinking was - generate a master clock signal at 76khz
Then setup an ISR to trigger on each rising edge of the PWM signal - how do I do this?
If I could trigger an interrupt to fire at 76khz ( or maybe use a timer ISR instead? ) - I could implement both the 19khz pilot tone as well as the 38khz multiplexing of the two pins.
How does this sound? |
|
|
bkamen
Joined: 07 Jan 2004 Posts: 1615 Location: Central Illinois, USA
|
|
Posted: Sat Jun 19, 2010 1:11 pm |
|
|
vsmguy wrote: | bkamen,
you got it :-D
What I was thinking was - generate a master clock signal at 76khz
Then setup an ISR to trigger on each rising edge of the PWM signal - how do I do this?
If I could trigger an interrupt to fire at 76khz ( or maybe use a timer ISR instead? ) - I could implement both the 19khz pilot tone as well as the 38khz multiplexing of the two pins.
How does this sound? |
You're going to want to do the math. IRQ at 76,000 times per second might be a little rough for a 10MIPS PIC DEPENDING on what else you have going on.
What are you trying to do with this?
Let's see... 76,000 is 13uS between pulses.
With a PIC running at 10MIPS (18F where Fosc == 40MHz) a single instruction is 100nS.
That means that between interrupts, you can execute 131 instructions.
That's pretty slim but possible if that's ALL the PIC is doing.
-Ben _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
|
|