Why are we talking about timers at all? It is a pain in the next to get an instruction cycle accurate pulse when using a timer. It is much easier to generate a pulse of an exact number of instruction cycles using a delay loop. ~ Bob Ammerman RAm Systems -----Original Message----- From: piclist-bounces@mit.edu [mailto:piclist-bounces@mit.edu] On Behalf Of Allen Mulvey Sent: Friday, July 18, 2014 10:40 AM To: 'Microcontroller discussion list - Public.' Subject: RE: [Pic] Making a special timer! MikroElektronika has a free Timer Calculator that you can use to get the code to set up your timer. I don't understand why anyone would want to use = a PWM when the timer is so easy and quite accurate. Check this out: http://www.libstock.com/projects/view/398/timer-calculator I use it all the time. For a PIC16 Timer1 you can get 100ms from this code: //Timer1 //Prescaler 1:8; TMR1 Preload =3D 3036; Actual Interrupt Time : 100 ms =20 //Place/Copy this part in declaration section void InitTimer1(){ T1CON =3D 0x31; TMR1IF_bit =3D 0; TMR1H =3D 0x0B; TMR1L =3D 0xDC; TMR1IE_bit =3D 1; INTCON =3D 0xC0; } =20 void Interrupt(){ if (TMR1IF_bit){=20 TMR1IF_bit =3D 0; TMR1H =3D 0x0B; TMR1L =3D 0xDC; //Enter your code here } }=20 Enable the interrupt. Turn on your pin. Count 10 interrupts. Turn off pin. Turn off and reset timer. Start over when necessary. You may need to make minor adjustments (TMR1L) for the time to actually tur= n the pin on and off. Allen > -----Original Message----- > From: piclist-bounces@mit.edu [mailto:piclist-bounces@mit.edu] On=20 > Behalf Of > Richard R. Pope > Sent: Friday, July 18, 2014 7:22 AM > To: Microcontroller discussion list - Public. > Subject: Re: [Pic] Making a special timer! >=20 > Joe, > Now I understand. We don't have to worry about having a reset=20 > pulse that is too short. Go high, wait one instruction, go back low.=20 > Put this in the main loop. It will always be 400ns long. Correct? > Thanks, > rich! >=20 > On 7/18/2014 6:10 AM, IVP wrote: > >> Well the PWM is out. Are you trying to say that we only need the=20 > >> 20ns? What if we are off a little bit and the reset pulse is only=20 > >> 19ns long. Wouldn't it be better to use a longer pulse to insure=20 > >> that we always meet that 20ns requirement? > > The instruction cycle time is 200ns, so you can't have a pulse=20 > > shorter than that. The shortest safest piece of code is > > > > bsf pulse > > nop > > bcf pulse > > > > which will give you at least 400ns > > > > Note the NOP in the middle. Because of the read-modify-write issue=20 > > on the PICs without an output latch, a NOP is recommended > > > > http://www.piclist.com/techref/readmodwrite.htm > > > > And my real-world submission to the SX list > > > > http://www.piclist.com/techref/scenix/sxrmw.htm > > > > Joe >=20 > -- > http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive=20 > View/change your membership options at=20 > http://mailman.mit.edu/mailman/listinfo/piclist -- http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive View/chang= e your membership options at http://mailman.mit.edu/mailman/listinfo/piclist --=20 http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .