Why don't you try an interrupt driven timer then it will execute the code in your main loop once every 20mS /1Sec/1Min ect... needs a variable for each group and a flag register to signify its time to do each activity. All runs of the system clock and uses TMR0 or TMR1 heres a little snippet from the ISR that sets up a tick. ;------------------------ INTERUPT PROCESS-------------------------------------- TMR1_ISR ;------------------------ An interrupt (based on 4MHz crystal)-------------- ;------------------------TMR1H (F3) TMR1L (CE) 25mS---------------------------- ;------------------------TMR1H (CF) TMR1L (2B) 100mS--------------------------- ;------------------------TMR1H (FB) TMR1L (21) 10mS---------------------------- BCF PIR1,TMR1IF ; CLEAR INT FLAG BSF TICK ; SET 10ms FLAG MOVLW 0F3h ; RELOAD VALUE FOR TMR1H (10ms) MOVWF TMR1H ; SAVE IN REG MOVLW 0CEh ; RELOAD VALUE FOR TMR1L MOVWF TMR1L ; SAVE IN REG MOVLW B'00110001' ; PSCALE 8 INT AND ON AND SYNC MOVWF T1CON ; FIT IT RETURN Steve -----Original Message----- From: piclist-bounces@mit.edu [mailto:piclist-bounces@mit.edu] On Behalf Of solarwind Sent: 16 August 2009 03:31 To: PICLIST Subject: [EE] How to generate a 1000 Hz pulse? (and PIC timers) To get accurate speed readings for my bicycle speedometer project, I have to count how long it will take the wheel to turn rather than how many times it has turned in x seconds. I want a 1 second speed update rate so to go about it, I need to count how many milliseconds it takes for the wheel to spin once. That way, I can get an accurate speed reading. So, I need some way to generate and count a 1000 Hz pulse. How would I do that? One idea is, I could use a (16 bit) timer on a PIC (16 bit would allow for a 65 second count using a 1 KHz pulse) and count up (can a PIC timer count up (not down)?). I can use an external crystal for the timer and divide it down to 1000 Hz (can I divide an external clock signal down?). That way, once I have the timer counting at 1000 Hz, I can read and reset the timer every time the reed switch is pulsed. For example, if it takes 0.764 seconds for the wheel to spin once, the timer would read 764 just before being reset for the next count. I could use 2 magnets on opposite ends of the wheel for greater accuracy (and balance). Would this work? -- [ solarwind ] -- http://solar-blogg.blogspot.com/ -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist