Any thoughts on this? I don't think libraries should be dependant on a specific timer, the user should be able to choose what timer to use.
For example, the library timer0_isr_interval.jal is dependant on timer0. What if someone wants to use two libraries that are both dependant on timer0? Matt. On Aug 8, 3:21 am, mattschinkel <[email protected]> wrote: > Hey guys, I was thinking about creating a timer library for general > setup of a timer. It would be nice to have a library that will allow > users to choose a timer for use with other libraries. I need some > advise/assistance. > > My servo libraries allow the user to choose a timer via a constant for > example: > const SERVO_SLAVE_USE_TIMER = 1 -- choose a timer > > Here's how it is setup in my libraries. After doing the alias, I can > use the new aliases in the rest of the lib for whatever timer the user > selected. It may be better to place these aliases in their own new > timer lib. > > -- setup servo 1 to 8 timer aliases for the timer the user selected > if SERVO_SLAVE_USE_TIMER == 0 then > -- set special timer0 settings > t0con_psa = 0 -- assign prescaler to timer0 > -- set timer registers to timer0 > alias servo_slave_tmr is TMR0 -- timer interval > alias servo_slave_cs is T0CON_T0CS -- timer clock source > bit > alias servo_slave_ie is INTCON_TMR0IE -- interrupt enable > alias servo_slave_if is INTCON_TMR0IF -- interrupt overflow > bit > alias servo_slave_ps is T0CON_T0PS -- timer prescaler > select bits > alias servo_slave_on is T0CON_TMR0ON -- timer on > > if defined(TMR0H) then > const SERVO_SLAVE_TIMER_SIZE = 16 > else > const SERVO_SLAVE_TIMER_SIZE = 8 > end if > > elsif SERVO_SLAVE_USE_TIMER == 1 then > -- set special timer1 settings > ;t1con_tmr1on = 1 -- enables timer 1 > -- set timer registers to timer1 > alias servo_slave_tmr is TMR1 -- timer interval > alias servo_slave_cs is T1CON_TMR1CS -- timer clock > source bit > alias servo_slave_ie is PIE1_TMR1IE -- interrupt enable > alias servo_slave_if is PIR1_TMR1IF -- interrupt > overflow bit > alias servo_slave_ps is T1CON_T1CKPS -- timer prescaler > select bits > alias servo_slave_on is T1CON_TMR1ON -- timer on > > if defined(TMR1H) then > const SERVO_SLAVE_TIMER_SIZE = 16 > else > const SERVO_SLAVE_TIMER_SIZE = 8 > end if > elsif SERVO_SLAVE_USE_TIMER == 3 then > ;t3con_tmr3on = 1 -- enables timer 3 > -- set timer registers to timer3 > alias servo_slave_tmr is TMR3 -- timer interval > alias servo_slave_cs is T3CON_TMR3CS -- timer clock > source bit > alias servo_slave_ie is PIE2_TMR3IE -- interrupt enable > alias servo_slave_if is PIR2_TMR3IF -- interrupt > overflow bit > alias servo_slave_ps is T3CON_T3CKPS -- timer prescaler > select bits > alias servo_slave_on is T3CON_TMR3ON -- timer on > > if defined(TMR3H) then > const SERVO_SLAVE_TIMER_SIZE = 16 > else > const SERVO_SLAVE_TIMER_SIZE = 8 > end if > end if > > Timers are quite alike for all PIC's. There are a few differences > however: > 1. Timer 0 can be either 8 bit or 16 bit. I am able to detect the > size, as seen above. > 2. Timer 0 requires setting of t0con_psa = 0. I suppose I can check > if a tXcon_psa is defined for the selected timer, and set it to 0 if > required. Not sure if this setting will be the same on all PIC's. > 3. Prescaler means different things on different PIC's and timers. > > So, mainly I have an issue with #3. Is there any way to detect what > prescaler settings are available? Can constants or a constant array be > added to the device files (to hold prescaler speeds that are > available), or is it better to place it in a timer lib for each PIC? > > Is there even any efficient way to read these from any file microchip > provides? > > 18f4620 - Timer0 prescalers: > > 111 = 1:256 > 110 = 1:128 > 101 = 1:64 > 100 = 1:32 > 011 = 1:16 > 010 = 1:8 > 001 = 1:4 > 000 = 1:2 > > 18f4620 - Timer1 prescalers: > 11 = 1:8 > 10 = 1:4 > 01 = 1:2 > 00 = 1:1 > > 18f4620 - Timer2 prescalers: > 0 0= Prescaler is 1 > 01 = Prescaler is 4 > 1x = Prescaler is 16 > > 18f4620 - Timer3 prescalers: > 11 = 1:8 > 10 = 1:4 > 01 = 1:2 > 00 = 1:1 > > I haven't used timer2 much, not sure how it works (haven't had time to > check). For now, I only use timers 0, 1 & 3. I currently assume the > prescaler settings are the same as above for all PICs. Is it simply > safe enouf to assume this? > > Matt. -- 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.
