|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
||||
|
||||
|
Re: How to use a "Timer"
The new PIC is 8722 not 8720 and the processor runs at 40 MHz but the prescaler examples are assuming the procesor is running at 10 MHz.
This is the actual Pic18F8722 data sheet:http://www.kevin.org/frc/PIC18F8722_ds.pdf Quote:
|
|
#2
|
||||
|
||||
|
Re: How to use a "Timer"
Quote:
Code:
void Initialize_Clock(void)
{
/* Use Timer3 (16-bits) to control our clock */
/* timer set to 4 ms */
OpenTimer3(TIMER_INT_ON &
T3_16BIT_RW &
T3_SOURCE_INT &
T3_PS_1_8
);
// Maximum for 16-bit 65535 - 5000 (4ms) = 60535
WriteTimer3(CLOCKOFFSET); /* Preload timer to overflow after 4ms */
}
|
|
#3
|
||||
|
||||
|
Re: How to use a "Timer"
Sorry I ment the clock speed is 40 MHz but the timer incriments one every 4 of them. Same with the processor instructions cycle. It is 1/4 the speed of the clock.
The example has a 10MHz clock but but the acutal ticks on the timer are only 2.5 MHz so per second(assuming 1 to 1 prescale). So on the robot controller you have to multiply that number by 4 to get the real number of ticks per second( If you are going by the example in Kevin Watson's interrupt code or the data sheets). Last edited by 6600gt : 12-02-2006 at 14:20. |
|
#4
|
||||
|
||||
|
Re: How to use a "Timer"
Quote:
I've never heard of it running a 40MHz clock and none the tests I've run support that, they do however support a 10MHz clock. For example, the code example I posted previously is a 4ms clock. I preloaded the timer with 60535 so it would overflow 5000 ticks later (65535). 4ms / 5000 = 800 ns per tick 1 second / 800 ns = 1,250,000 ticks = 1.25 MHz 1.25MHz * 8 (1 to 8 prescale) = 10MHz If I missed something, can you point out where I can find it? I'm genuinely confused and I don't understand where you got your numbers from. Hopefully helping, Matt |
|
#5
|
||||
|
||||
|
Re: How to use a "Timer"
I am now confused too. This is what I know:
The PIC's have an internal hardware PLL(Phase Loop Lock hardware multiplier). I can't find the setup of this of RC but if you connect a 10MHz crystal to a pic and turn on hardware PLL, its like running 40 MHz crystal.(Don't ask me how it does it, I have no clue, try the data sheet) But they might have just hooked it up directly to a 40MHz clock, I guess you can do it. I see this everywhere Foso/4, I am guessing but I think it means frequency of the oscillator(clock). I might be screwing up the technical terms. In the Data Sheet I found this "One instruction cycle consists of four oscillator periods...". So 10 MIPS * 4 = 40MHz oscillator is just a crystal or resonator that oscillates or resonates at a particular frequency. Don't worry about it. All you need to know is that the processor executes at 10 MIPS |
|
#6
|
||||
|
||||
|
Re: How to use a "Timer"
Quote:
However you're right, basing the timers and ticks on 10 million a second works. Perhaps after ship you and I should take up a research project to demystify this? ![]() |
|
#7
|
||||
|
||||
|
Re: How to use a "Timer"
Quote:
I ordered a sample pack for free. I am currently working on 18F458. 10MIPS 32k code spack 1.5k RAM 256bytes EEPROM A free chip with similar processing power as the RC!! Though I took a little while to get it to work. I can run a servo directly off a pin on the chip!!! Where do you want to start? |
|
#8
|
|||||
|
|||||
|
Re: How to use a "Timer"
Quote:
Thanks, |
|
#9
|
||||
|
||||
|
Re: How to use a "Timer"
I am using a breadboard and a very cheap programmer(took me 20 hours of websurfing to find one that I could buy all the parts at radioshack).
http://www.picbasic.co.uk/forum/arch...php/t-703.html You will need a data sheet for your particular pic. PGD = data PGC = clock Vss = ground Vpp/Vdd = power All you need is a serial plug and some wire and registers. Software is http://www.ic-prog.com/ I prefer the 18F series chips because the C18 compiler is readily available. Unless you want to program in assembly, then you can get any pic. Just order a sample pack(up to 15 chips) umm....chips To date I have only ordered one sample pack with 12 16f series chip and 3 18f series. A good free compiler for the 16f series has been hard to find. Another big plus for 18F series is that you can easily use the code written by Kevin Watson, with a few modifications. In fact, I looked through the IFI default code to understand the structure and impliment it into my pic. |
|
#10
|
|||
|
|||
|
Re: How to use a "Timer"
Quote:
The PIC18F8720 (and presumably others) has a PLL as an option. This allows you to multiply the frequency of the oscillator that is used as the clock source. Whether IFI impliments this or not, I don't know (their website only quotes 10MIPS). So, if we have a 10MHz crystal and take advantage of the PLL, the PIC sees a 40MHz crystal. The datasheet mentions that this would be good to do of you are worried about having external high frequency signals. The Foso/4 you see refers to what the PIC does with the clock. Each instruction cycle is 4 clock cycles. If you connect a 40MHz crystal, instructions are 10MHz. The details should be in the datasheet, but in essence, it takes the processor 4 clock cycles to process an instruction. What you need to take away from this: The PIC in the RC is 10MIPS. |
|
#11
|
|||
|
|||
|
Re: How to use a "Timer"
How do I use another timer? The way I'm having things work right now, I'm already using Timer 1 to do something. Now I want another timer to do something else? How can I do that? And if there are two timers firing interrupts at the same time, is that going to mess things up? I heard that the five timers in the FRC are all different, so how do I use another timer?
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|