Searching \ for 'Delay routines in C' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/timers.htm?key=delay
Search entire site for: 'Delay routines in C'.

Truncated match.
PICList Thread
'Delay routines in C'
1999\01\14@183025 by Jeff Wicklein

picon face
I am trying to come up with a delay routine in for milliseconds using a 480kHz
oscillator and the PIC16C73A.  Every routine that I try (even inline
assembler) gives me at least 2ms error.  I am using the Hi-tech compiler and
really need help on this.

Thanks.

jeff

1999\01\14@191240 by Paul-R.-Smargiassi

flavicon
face
part 0 5901 bytes
eff I am using an Interrupt on the same processor to generate a delay that is 255 st ep variable. The max delay is 8.196 ms. I use a 8MHz crystal, so the prescale and post scale would need to be changed. If PR2 is set to zero, the compare will be missed and the time will be the max. The following is the intialization routine. // ---- Timer 2 provides a delay from zero cross to turning on the triac // the max delay for timer 2 is when PR2 reg is set for 255. // Timer 2 counts from zero to a compare with PR2 and causes an interrupt // At 8 MHz, count period = 1,000,000/(8/4) = 0.5 us // The prescale is set to 16 and the post scale is set to 4 for a 64:1 // 256 x 64 x 0.5 = 8.196 ms @ 2 Mhz T2CKPS1 = 1; T1CKPS0 = 1; // divide by 16 prescale TOUTPS3 = 0; TOUTPS2 = 0; TOUTPS1 = 1; TOUTPS0 = 1; // divide by 4 post scale TMR2IF = 0; TMR2IE = 0; // Timer is enabled in the interrrupt The following is the interrupt routine static void // interrupt general_int_service(void) { // GIE = 0; if (TMR1IF) // timer 1 overflow has occured { TMR1IF = 0; TMR1 = TMR1 - 62500; if (timer125 >= 7) { timer125 = 0; } else { ++timer125;} flag125 = timer125; toggle_flag = !toggle_flag; SPARE_2 = toggle_flag; } if ( ZERO_X_FLAG ) { // on zero cross, turn off the triac drive and start tim er 2 ZERO_X_FLAG = 0; OPTO_DRIVE = 0; // turn off the Triac dr ive TMR2IE = 0; // clear int en if necessary TMR2IF = 0; // clear flag PR2 = PR2_preload; TMR2 = 0; // clear any count TMR2ON = 1; // turn on the timer TMR2IE = 1; // enable interrupt OPTO_DRIVE = 0; // turn off the Triac dr ive Time_out_flag = 0; } if (TMR2IF ) { // when timer 2 int, turn off the timer and turn on tria c if in run mode TMR2IE = 0; // disable the timer TMR2IF = 0; // clear the int flag TMR2ON = 0; // clears pre and post scalers TMR2 = 0; // clear count Time_out_flag = 1; if ( Motor_run_flag ) { OPTO_DRIVE = 1; } else { OPTO_DRIVE = 0; } } // GIE =1; } // ***** end int service routine *********************** ***** I hope this helps, Write or call if you have questions. Paul Smargiassi Jeff Wicklein wrote: > > I am trying to come up with a delay routine in for milliseconds using a 480kHz > oscillator and the PIC16C73A. Every routine that I try (even inline > assembler) gives me at least 2ms error. I am using the Hi-tech compiler and > really need help on this. > > Thanks. > > jeff

NEW WORLD DIGITAL

19937 NE Woodinville Duvall Rd.

Woodinville, WA 98072-9499

Telephone: (425) 788-8081

Fax: (425) 788-6452

e-mail

Paul-R.-Smargiassi@worldnet.att.net




PRODUCT DESIGN AND DEVELOPMENT ENGINEERING SERVICES

Supporting companies that need to bring new products into prod uction, improve existing products, or need engineering and manufacturing problem solving and test fixtur e support.

NEW WORLD DIGITAL offers all the services required for Produc t Design and Development. The operation is organized for Flexible Response through a Matrix of Associates. We can deliver complete (turn key) solutions for new product needs or provide Problem Solving a nd Manufacturing Support on existing products.

FIELDS OF SPECIALTY

  • MECHANICAL & ELECTRONIC ENGINEERING
  • ELECTRO MECHANICAL & PACKAGING DESIGN
  • EMBEDDED SYSTEMS
  • PAL, GAL, GATE ARRAY LOGIC, DESIGN
  • INSTRUMENTATION
  • FLUID HANDLING
  • MEDICAL PRODUCTS
  • CONSUMER PRODUCTS
  • BIO-TECHNOLOGY
  • INDUSTRIAL CONTROL & ROBOTICS SYSTEMS
  • STEPPER AND SERVO MOTORS
  • SOFTWARE APPLICATIONS


ON SITE CAPABILITIES

PROTOTYPE AND MODEL SHOP

3D - COMPUTER AIDED DESIGN & PCB DESIGN

ELECTRONICS AND MECHANICAL DEVELOPMENT LAB.

INDUSTRIAL DESIGN, APPEARANCE MODELS

TURN KEY LIMITED PRODUCTION RUNS





CONTACT

PAUL SMARGIASSI

(425) 788-8081

1999\01\14@192057 by Paul-R.-Smargiassi

flavicon
face
Jeff

I am using an Interrupt on the same processor to generate a delay that
is 255 step variable.
The max delay is 8.196 ms. I use a 8MHz crystal, so the prescale and
post scale would need to
be changed.  If PR2 is set to zero, the compare will be missed and the
time will be the max.
The following is the intialization routine.

// ---- Timer 2 provides a delay from zero cross to turning on the
triac
// the max delay for timer 2 is when PR2 reg is set for 255.
// Timer 2 counts from zero to a compare with PR2 and causes an
interrupt
// At 8 MHz, count period = 1,000,000/(8/4) = 0.5 us
// The prescale is set to 16 and the post scale is set to 4 for a 64:1
// 256 x 64 x 0.5 = 8.196 ms @ 2 Mhz

       T2CKPS1 = 1;    T1CKPS0 = 1; // divide by 16 prescale
       TOUTPS3 = 0;    TOUTPS2 = 0;    TOUTPS1 = 1;    TOUTPS0 = 1;
// divide by 4 post scale
       TMR2IF = 0;
       TMR2IE = 0;     // Timer is enabled in the interrrupt

The following is the interrupt routine

static void              //
interrupt general_int_service(void)
{
//      GIE = 0;
       if (TMR1IF)             // timer 1 overflow has occured
       {
               TMR1IF = 0;
               TMR1  = TMR1 - 62500;
               if (timer125 >= 7)
                       {       timer125 = 0; }
               else
                       {       ++timer125;}
               flag125 = timer125;
               toggle_flag = !toggle_flag;
               SPARE_2 = toggle_flag;
       }

       if ( ZERO_X_FLAG )
               {       // on zero cross, turn off the triac drive and
start timer 2
                       ZERO_X_FLAG = 0;
                       OPTO_DRIVE = 0;                 // turn off
the Triac drive
                       TMR2IE  = 0;    // clear int en if necessary
                       TMR2IF  = 0;  // clear flag
                       PR2 = PR2_preload;
                       TMR2            = 0;    // clear any count
                       TMR2ON  = 1;    // turn on the timer
                       TMR2IE  = 1;    // enable interrupt
                       OPTO_DRIVE = 0;                 // turn off
the Triac drive
                       Time_out_flag = 0;
               }
       if (TMR2IF )
               {       // when timer 2 int, turn off the timer and
turn on triac if in run mode
                       TMR2IE  = 0;            // disable the timer
                       TMR2IF  = 0;            // clear the int flag
                       TMR2ON  = 0;            // clears pre and post
scalers
                       TMR2            = 0;            // clear count
                       Time_out_flag = 1;
                       if ( Motor_run_flag )
                               { OPTO_DRIVE = 1; }
                       else { OPTO_DRIVE = 0; }
               }
//      GIE =1;
}                       // ***** end int service routine
****************************

I hope this helps,  Write or call if you have questions.

Paul Smargiassi
NEW WORLD DIGITAL
spam_OUTPaul-R.-SmargiassiTakeThisOuTspamworldnet.att.net
PRODUCT DESIGN AND DEVELOPMENT ENGINEERING SERVICES
Supporting companies that need to bring new products into production,
improve existing products,
or need engineering and manufacturing problem solving and test fixture
support.

Jeff Wicklein wrote:
>
> I am trying to come up with a delay routine in for milliseconds using a 480kHz
> oscillator and the PIC16C73A.  Every routine that I try (even inline
> assembler) gives me at least 2ms error.  I am using the Hi-tech compiler and
> really need help on this.
>
> Thanks.
>
> jeff

1999\01\15@071013 by Michael Rigby-Jones

flavicon
face
Take a look at the DELAY.H and DELAY.C files in the Samples directory of
your C compiler of if you don't have them, download them from the HiTech web
site

Regards

Mike Rigby-Jones
.....mrjonesKILLspamspam@spam@nortelnetworks.com

{Quote hidden}

More... (looser matching)
- Last day of these posts
- In 1999 , 2000 only
- Today
- New search...