Hi Matt,

About the prescaler -- the timer0_isr_interval.jal shows one example
of how to deal with the prescaler - check out its init routine.

William


On Feb 24, 1:28 am, mattschinkel <[email protected]> wrote:
> Thanks william, I will review your modifications, This is just a very
> basic sample to show the usage of timer3. Timer1 works the same as
> timer3 so I may write or copy this sample into a timer1.
>
> I do know that the timer should be reloaded at the beginning of the
> interrupt, but if the timer is very low the interrupt routine will not
> complete since it will get interrupted again. I will move it and put a
> note.
>
> A constant such as "const Hz = 100" is nice to have, but then you have
> to do other calculations if you use the prescaller. I have been
> thinking about making a frequency generator lib that would work in
> this fashon. There is also a limit since accuracy would get worse at
> high speeds.
>
> I would actually like to see a constant like this in the PWM lib/
> sample. I don't quite remember the PWM stuff, but I do remember that I
> did not like it when I tried it since I could not set the frequency
> with a constant. I also did not like the low frequency limit of 300hz,
> I wanted something lower.
>
> Thanks,
> Matt.
>
> On Feb 23, 8:29 pm, William <[email protected]> wrote:
>
>
>
> > On Feb 12, 11:39 pm, mattschinkel <[email protected]> wrote:
>
> > > I have been speaking on jallist about timer3, Rob suggested that I add
> > > this as a sample. This sample shows basic usage of timer3. Thanks for
> > > your help Rob.
>
> > Hi Matt,
>
> > I haven't been able to monitor the JALLIST and JALLIB much recently,
> > and was working on using timer3 in a 18F2585 project tonight.  I had
> > studied the datasheet and Rob's device file for the 18F2585, and was
> > about to start typing in from scratch, when I decided to search the
> > 'samples' directory for any reference to timer3. Bingo!
>
> > Nice job, really made me have more confidence that this thing would
> > work, and it did!
>
> > You may find my small changes worth a look.  I wanted to be able to
> > modify the interrupt rate with just a simple constant.  Also, it
> > seemed good to me to use the prescaler, and also, to reload the timer
> > as early as possible in the interrupt routine. Otherwise, you will
> > gradually lose more and more time, due to interrupt latency.
>
> > Lastly, I've learned from bad experiences, that is is best not to
> > enable the actual interrupt mechanism, until after you have completely
> > configured the hardware.  Otherwise, you might find a weird case where
> > the timer goes crazy interrupting you while you are still trying to
> > set it up, and you have to re-set the chip manually, etc.
>
> > -- 1:8 prescaler, 20MHz crystal, 100Hz desired
> > const Hz = 100
> > const word tmr_preload =  0x10000 - (target_clock / Hz / 4 / 8)
> > T3CON_RD16 = 1
> > T3CON_T3CKPS = 3
> > T3CON_TMR3CS = 0
> > TMR3 = tmr_preload
> > T3CON_TMR3ON = 1
>
> > procedure tmr3_isr() is
> >    pragma interrupt
> >    if PIR2_TMR3IF then
> >       TMR3 = tmr_preload
> >       PIR2_TMR3IF = off
> >       led = led ^ 1
> >    end if
> > end procedure
>
> > PIE2_TMR3IE = 1
> > INTCON_PEIE = 1
> > INTCON_GIE = 1
>
> > forever loop
> > end loop

-- 
You received this message because you are subscribed to the Google Groups 
"jallib" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/jallib?hl=en.

Reply via email to