CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Synchronize two frequencies - main signal from the PWM Pin

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
vsmguy



Joined: 13 Jan 2007
Posts: 91

View user's profile Send private message Visit poster's website

Synchronize two frequencies - main signal from the PWM Pin
PostPosted: Thu Jun 17, 2010 12:35 pm     Reply with quote

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

View user's profile Send private message

Sync'd PWMs
PostPosted: Sat Jun 19, 2010 10:00 am     Reply with quote

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

View user's profile Send private message

Re: Synchronize two frequencies - main signal from the PWM P
PostPosted: Sat Jun 19, 2010 10:45 am     Reply with quote

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

View user's profile Send private message Visit poster's website

PostPosted: Sat Jun 19, 2010 11:15 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Jun 19, 2010 1:11 pm     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group