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 support@ccsinfo.com

External Oscillator & Timers + PWM

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



Joined: 23 Apr 2005
Posts: 73

View user's profile Send private message Send e-mail AIM Address

External Oscillator & Timers + PWM
PostPosted: Fri Sep 29, 2006 12:33 pm     Reply with quote

I am using an external 20MHz crystal as the timing mechanism on my PIC18F2580. I am trying to create a PWM with a couple of timers, but I cannot get timer0 to run off of the external oscillator. I know the oscillator (crystal) itself is working correctly because I have tested it using a blinking LED routine in main with 100ms delays that run off of its signal. Here are a few questions I have that I have been unable to figure out:


1. Is setup_timer_0(RTCC_EXT_L_TO_H) the wrong way to setup this timer to work with my external crystal? (This hasn't been working for me)
and what fuses should I use? (On this note, is there a reference somewhere that describes all of the available fuses and what they mean? I have been unable to find this anywhere)


2. How would I configure timer1, timer2, and timer3 to operate using this external crystal?


3. I need to generate an outgoing PWM signal that is not a consistent duty cycle on any given period although the period itself is consistent - for example: I may need to have high 10us, low 40us on the first 50us period but then high 40us and low 10us on the next 50us period. The catch is that there can be no gap between periods - it must be one continuous signal so I am worried about changing timer setups between periods to create the correct duty cycle signal. Is there an easier way to do this than just using 2 timers and generating a custom PWM signal?


4. I need to be able to detect pulse widths for incoming signals - is the best way using a timer and reading the value of the timer when a '1' to '0' transition is detected and determine the width from that readout? I am also not quite sure how to detect the transition in a timely fashion...maybe by polling the pin?


I realize that this is a lot in one post, but any help would be appreciated!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Sep 29, 2006 1:02 pm     Reply with quote

Quote:

Is setup_timer_0(RTCC_EXT_L_TO_H) the wrong way to setup this timer
to work with my external crystal? (This hasn't been working for me)

Look at the data sheet, in the Timer0 section. There's a block diagram
of the timer. When "External clock" is enabled, the timer runs off a
clock signal from the TOCKI pin. Look at the pin diagram on page 4
of the data sheet. That's pin RA4.

But your 20 MHz crystal is on the OSC1 and OSC2 pins. Those are
entirely different pins.

Quote:
I cannot get timer0 to run off of the external oscillator

The "external" crystal is used by the PIC to create an internal clock
which is 1/4 of the crystal frequency. This "internal" clock is what
is normally used to run all the timers. Just use the RTCC_INTERNAL
parameter and "OR" it with the appropriate divisor value. See the .H
file for your PIC for the constants that may be used with setup_timer_0().

Quote:
I may need to have high 10us, low 40us on the first 50us period
but then high 40us and low 10us on the next 50us period.

This sounds like some type of signaling.

I think you need to tell us your application.
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