Click here to Skip to main content
16,020,714 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everybody;

I was finish build the complete circuit for Ultrasonic measure distance..

and I start to write the PWM code and generate 10 pulse from RC2 thats is working,
but
1.I want to generate another High signal it will be start when pulse start and stop at same time this one for detected signal?..
2. when I write the code to start counter?
can you help me???

LIST P=16F877A
#INCLUDE P16F877A.INC
cblock 0x20 ;start of general purpose registers
PULSE_COUNT 
count ;used in delay routine
count1 ;used in delay routine
temp ;temp storage
TIMEL
TIMEH
LOW_COUNT
HIGH_COUNT
LOOP_COUNT
endc
ORG 0x0000
GOTO START
ORG 0x0010
INIT_RC
CLRF PORTC
BSF STATUS,RP0
MOVLW B'00000001'
MOVWF TRISC
BCF STATUS,RP0
RETURN 
SEND
MOVLW D'10'
MOVWF PULSE_COUNT
CALL PWM
RETURN
START 
CALL INIT_RC
CALL INIT_PWM
CALL SEND

INIT_PWM
CLRF TIMEL
CLRF TIMEH
CLRF CCP1CON
CLRF TMR2
MOVLW D'12'
MOVWF CCPR1L
CLRF INTCON
BSF STATUS,RP0
MOVLW D'24'
MOVWF PR2
BCF TRISC,2
BCF STATUS,RP0
CLRF PIR1
MOVLW 0X0C
MOVWF CCP1CON
BSF T2CON,TMR2ON
BCF PORTC,1 
RETURN
PWM
BTFSS PIR1,TMR2IF
GOTO PWM
BTFSC PORTC,2
BSF PORTC,1
BCF PIR1,TMR2IF
DECFSZ PULSE_COUNT
GOTO PWM
BCF PORTC,1
CLRF CCPR1L
CALL Delay500
MOVLW D'10'
MOVWF PULSE_COUNT
RETURN

Delay500
movlw d'3' ;delay for500us
movwf count1
Delay1 call Delay250
decfsz count1
goto Delay1
return
Delay250 
movlw d'125' ;delay for250us
movwf count
goto Delay
Delay ;delay for2us
nop
nop
decfsz count, f
goto Delay
return

END
Posted
Updated 12-May-11 6:25am
v2

Hello,

You might get a more quicker reply if you try your queries in any of the PIC related forums like

Microchip Forum [^]

Forum 2[^]


Forum 3[^]


About your Question :

1. Are you talking about Generating a Square wave that has the time period of the PWM wave front ?

2. What counter are you talking about ?

BR//
Harsha
 
Share this answer
 
v2
Comments
ZeeroC00l 12-May-11 12:51pm    
If you have already generated a square wave of 40KHz and 250us, then why exactly you want to generate another wave of the same time and frequency at the same time ?

If you want to do so anyways, why not use two timers or use CCP modules in PIC 877A along with a timer ?
yes I Generating a Square wave 40KHz for 250us..

I mean count time for measure the distance..

can you help me?????
 
Share this answer
 
v2
Comments
ZeeroC00l 12-May-11 12:42pm    
Please post questions or clarifications related to an answer as a comment to that so that the user can be notified about that.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900