# 8051 Double pulse generator

Status
Not open for further replies.

#### 98Altima

##### Newbie level 2
I am trying to generate a double pulse, say 2us long @ 500hz, only twice every 2 periods... to get an average of 250hz.

___|_|___|_|___|_|___|_|___

Any one have any good ideas on where to start? I am fairly new to programming but cant definitly find my way around. I have a project in need of this input, and instead of ordering some expensive signal generator way out of my price range im trying to accomplish this with a C8051FX20 dev kit.

Thanks for all replies!

#### IanP

The easy way is to use delay(s), more advanced (and more accurate) solution will involve timers and interrupts ..
So, just to give you something to start with, here is an example of the first approach:
Code:
…
CLR	P1.X		; X is your output pin
…

MOV	B, #0FFh
DJNZ	B, $; 256 cycles delay, time will depend on your clock .. ; this can be repeat as many times as necessary .. Loop1: SET P1.X NOP ; SET and NOP give you 2 cycles delay, … ; add as many NOPs as required for 2us .. CLR P1.X MOV B, #0FFh DJNZ B,$		; 256 cycles delay, time will depend on your clock ..
…			; this can be repeated as many times as necessary ..
MOV	B, #0FFh
DJNZ, B, $SET P1.X NOP ; SET and NOP give you 2 cycles delay, … ; add as many NOPs as required for 2us .. CLR P1.X MOV B, #0FFh DJNZ B,$		; 256 cycles delay, time will depend on your clock ..
…			; this can be repeated as many times as necessary ..
MOV	B, #0FFh
DJNZ, B, \$

SJMP loop1

:wink:
IanP

#### 98Altima

##### Newbie level 2
Should have stated most my experience is in C :-?

Very much appreciate the example though, i figured as much with interrupts and timers. just wanted some validation from someone.

I'll give this a shot tomorow, thanks much IanP

Status
Not open for further replies.