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.

Variable delay using pic

Status
Not open for further replies.
Well where you start lets see how would we know, you didn't say what your using C Basic or ASM.

Next from no delay to how long would be nice to know.

And last how you want to change it would be nice.


But you can do it like this varD hold any number you want take a ADC pin with a pot that gives you 1024 steps from varD use the pot to lower or increase varD then cast that to your delay function.
 
If you use MikroC, it'll just be:
Delay_ms(put in any number of milliseconds you want);

Eg:
Code:
Delay_ms(1000);

That's it. One line of code. But if you want to make it from start, then it's just like:

Code:
void delay (unsigned int delay_val){

for(x=0;x<=delay_val;x++)

}

So delay_val is the value you define. 1000 means a thousand instruction cycles, depending on your PIC's oscillator frequency.
 
thank you for response.. I am using ASM language, I need to give delay from 5 seconds to 30 seconds delay.
Well where you start lets see how would we know, you didn't say what your using C Basic or ASM.

Next from no delay to how long would be nice to know.

And last how you want to change it would be nice.


But you can do it like this varD hold any number you want take a ADC pin with a pot that gives you 1024 steps from varD use the pot to lower or increase varD then cast that to your delay function.
 
Check my PIC tutorials - most of them include simply delay routines using nested loops.

If you also check the PICList there's a 'delay code generator', which generates the delay code for you - so you could generate a delay of (say) 100mS, and then call that the number of times you want for your specific delay.
 
Thanks for your reply. But, i just wandering how to write a code variable delay ( i need 5s to 30 seconds delay)
thank you
check my pic tutorials - most of them include simply delay routines using nested loops.

If you also check the piclist there's a 'delay code generator', which generates the delay code for you - so you could generate a delay of (say) 100ms, and then call that the number of times you want for your specific delay.
 
This gives you a 1 second delay call it in a loop how many time you want it to be

Code:
	cblock
	d1
	d2
	d3
	endc

			;999997 cycles
	movlw	0x08
	movwf	d1
	movlw	0x2F
	movwf	d2
	movlw	0x03
	movwf	d3
Delay_0
	decfsz	d1, f
	goto	$+2
	decfsz	d2, f
	goto	$+2
	decfsz	d3, f
	goto	Delay_0

			;3 cycles
	goto	$+1
	nop
 
I don't he hasn't said much to go by so I just posted something to start with. LOL
 
Status
Not open for further replies.

Latest threads

Back
Top