Society of Robots - Robot Forum
Software => Software => Topic started by: Tomomastchi-project on December 28, 2008, 02:02:22 PM
-
Hi guys,
I have a few questions concerning oscillators and PIC controllers. I am currently using a PIC 18F4550 with the C18 compiler. I am not using any usb stuff.
- In my scheme I hooked up a crystal and two capacitors onto pin 13 and 14 (OSC1 & OSC2). What is it for?
- Does a uC have something like a clock, which you can, for example, ask how long the program has been running or which you can use to measure intervals?
- What is the clockspeed of these controllers? How long is an instructioncycle?
- What does #pragma config OSC = XT do?
- What are these "oscillator modes"?
-
I have a few questions concerning oscillators and PIC controllers. I am currently using a PIC 18F4550 with the C18 compiler. I am not using any usb stuff.
Are you USING or TRYING to use? It makes a huge difference: If you're USING we know for sure you got an working circuit. If you're trying to use then we know your circuit might not be working.
In my scheme I hooked up a crystal and two capacitors onto pin 13 and 14 (OSC1 & OSC2). What is it for?
That's what provides the "clock" for the MCU. Did you create your own scheme or are you looking at a scheme that's known to be working?
Does a uC have something like a clock, which you can, for example, ask how long the program has been running or which you can use to measure intervals?
The uC has "Timers"; Don't use the term "Clock" for this because that's usually used for the signal that drives the MCU. That is, the Clock comes from the external oscillator OR from the internal RC network. Take a look at the datasheet, all timers are explained in some detail. Using the timers might not be as easy as we'd all want it, maybe you should do something simpler with the MCU and then move on to Timers - just to lessen the learning curve.
What is the clockspeed of these controllers? How long is an instructioncycle?
The clock speed depends on the oscillator mode you selected and on the external oscillator you used. If you used an 8Mhz external oscillator then you'd get 8Mhz clock speed. The datasheet for the PIC18F4550 says it can go up to 48Mhz.
There are two kinds of instructions on the 8 bit PIC microcontrollers (PIC18 is an high-end 8 bit microcontroller): There are normal instructions and branching instructions. All normal instructions take 4 clock cycles to complete. Branching instruction take 4 or 8 clock cycles to complete (if no branching occurs then the instruction takes 4 cycles. If branching occurs then it takes 8 instructions).
Example: If you run an 48Mhz clock then you'd have 48,000,000 clock cycles per second so you'd get 12,000,000 "normal" instructions per second or 6,000,000 branching instructions per second. Doing 1/12,000,000 we get 83,33 µs for one instruction (there are 10^9 µs in one second)
What does #pragma config OSC = XT
I assume that sets the oscillator mode to be "XT". You'll need to look into your datasheet to see what other oscillator modes are available for your particular part.
What are these "oscillator modes"?
It all depends on the part you're using, you'll need to look into your datasheet. Not all parts have the same oscillator modes but they have similar oscillator modes. Your part (the PIC18F4550) has 12 different oscillator modes!
-
I haven't built the hardware yet, but my friend is now routing the scheme. We used the oscillator in http://1.bp.blogspot.com/_een4QiFVyl4/SJQgWaldFMI/AAAAAAAAAw4/1Sc8iprVeVc/s1600-h/pic18.jpg (http://1.bp.blogspot.com/_een4QiFVyl4/SJQgWaldFMI/AAAAAAAAAw4/1Sc8iprVeVc/s1600-h/pic18.jpg) for our scheme.
After reading the datasheet I came to the conclusion that if we use a 20Mhz Crystal osciallator, we have to use two 15pF capacitors.
What are the configurations for WinPic800 in that case? What should I configure in the C sourcecode?