1us Delay using 89c2051
Discussion in "8051 Discussion Forum" started by jackthegr8 Nov 9, 2009.
Mon Nov 09 2009, 05:23 pm
Hey all, I do use atmel 89c2051 controller. I wanna generate a signal with 1us On time and 1us OFF time. I am tired of trying with different method. so plz suggest me some idea !!!
Mon Nov 09 2009, 06:17 pm
you can generate 1uS delay for the reason, your single clock cycle itself is 1.085uS. you need higher speed crystal to generate that delay.
Mon Nov 09 2009, 06:29 pm
Ok. My intention is not exactly producing 2us delay. I need to generate a On time of 3 us and off time 27 us. Pulse of 10% duty cycle. and this dut cyle is variable from 10% to 90%
Mon Nov 09 2009, 08:58 pm
One simple solution is to change your crystal frequency to 12Mhz to get exactly
1us / 1 Byte Command
example
2uS ON
3uS Off
1us / 1 Byte Command
example
2uS ON
3uS Off
main: setb P1.0 ;1us nop ;1uS clr P1.0 ;1us jmp main ;2us
Tue Nov 10 2009, 12:23 pm
Yep, thanks for the code, but i am looking for implement the same using timer or DJNZ loop, so that I can change the delay in a generic way.I attempted using timer, but I couldn't get On or OFF period lesser than 5 ns.
Tue Nov 10 2009, 06:06 pm
well you can use loops if your delay is a bit longer but DJNZ instruction itself take 2 cycles.
Wed Nov 11 2009, 02:31 pm
void delay_us(unsigned int us)
{
int a=(us)/13; //BY TRIAL
while(a--);
}
11.0592*2 MHZ
{
int a=(us)/13; //BY TRIAL
while(a--);
}
11.0592*2 MHZ
Wed Nov 11 2009, 05:54 pm
mov R1,#01 ;or any other value here
djnz R1,#01,decrement
decrement: dec R1
That is with a 12Mhz crystal. However, minimum with djnz is 2us!
djnz R1,#01,decrement
decrement: dec R1
That is with a 12Mhz crystal. However, minimum with djnz is 2us!
[ Edited Wed Nov 11 2009, 05:55 pm ]
Powered by e107 Forum System