Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

calculation error

Status
Not open for further replies.

kichapi

New Member
i used interrupt add my adc program and some doubt the calculation.
my operating frequancy 20mhz. i want20us delay .how to calculate this?
please help me? iam waiting your valid replay

fout=fclk/prescaler*(256-TMR0)*count=?
 
I guess that you are using a 16F series PIC. For those, the PIC takes 4 clock cycles to execute one instruction.

A 20 MHz clock has a cycle time of 50 ns so 4 cycles is 200 nS. A 20 µs delay is 100 instruction cycles.

A delay loop of 100 cycles would look something like this:-
Code:
      movlw    d'33'
      movwf   delay_reg ; You need to define a register for this
delay_loop
      decfsz    delay_reg, f
      goto       delay_loop

That just goes round the loop 33 times. The GOTO instruction takes 2 instruction times, so the loop takes 3 instruction times. Running it 33 times takes 100 cycles (might not be exact, but it is close) so just about 20 µs at 20 MHz
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top