Thanks Jinx, I hope I could have at least 25 % of your knowledge on PICS some time! Below my comments... On 7/21/07, Jinx wrote: > > > I've included a counter that is being decremented while a square > > signal is generated. Depends on the counter whether the signal > > stops or continues. However, instead of this counter, I need to > > have a timer that in case these pulses have been reproduced for > > up to 30 seconds, a "time out" makes it stop. I understand I > > need a timer interruption to do that (and use Timer 0 because > > I'll use PWM module later) > > I think I understand what you want to do. Make square waves > for 30 seconds and then stop ? Exactly. What annoys me much is that I want to make use of this time out and at the same time -simultaneously- I need to control the signal I'm generating because it will have not always the same frequency neither the same duty cycle. It depends on the value retrieved from the table. (By the way, this poor table was meant to convert frequency values, received from RS232 transmission, to period values so as to generate these pulses -with duty cycle information also received from RS232-). Some possibilities - > > (1) TMR0 + pre-scaler + counter > (2) TMR1 + pre-scaler + counter > (3) TMR1 with a 32kHz crystal > > (1) & (2) TMR0 / TMR1 > > You didn't say what frequency you're running. I'll assume 4MHz as > you've got XT selected => 1us cycle time > > 30 seconds = 30,000,000us. If TMR0 pre-scaler = 256 then > => (30000000/65536) = 457 rollovers + 50048 cycles > > So you could set TMR0 to free run and detect TMR0IF=1 (with > or without interrupts). Increment a counter and look for the second > time it reaches (457-256) = 201, then load TMR0 with -195 to do > the last part (just over 50ms) of the 30 seconds. Because the > pre-scaler is set to 256, you will be off by 128us, as 50048/256 > = a 195.5 count in TMR0. You could switch the pre-scaler to a > lower value (128 ?) to get the timing more accurate > > TMR0 with 1:256 pre-scaler is the same as TMR1 without a pre- > scaler. TMR1 can have a 1:8 pre-scaler > > As above, 30000000/65536/8 = 57 rollovers + 14448 cycles > > (3) TMR1 + crystal > > This might be the easiest. TMR1 with no pre-scaler running at > 32768Hz will rollover every 2 seconds. Re-load TMR1 with > 0x8000 will make that 1s, 0xC000 for 0.5s and so on I really appreciate all your explanation. It is very clear for me, in fact I was thinking make a try with the first alternative but those 457 rollovers scare me:o) What may be not clear enough for me is the way I can implement the third option (32 KHz crystal). > (and use Timer 0 because I'll use PWM module later) > > You might want to check whether PWM will go as slowly as > you need Yes, at the very beginning I thought I could use this module to generate my signal but possile frequencies are between 2 - 120 Hz. -- > 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