Pulse generation using PIC12f629

Status
Not open for further replies.

VRL_15

New Member
I am using PIC12f629 to generate a pulse and I want the on time 44ms and off time 44 ms(millisec).
Please let me know a code that will generate this pulse.

Thanks and Best Regards
 
list p=12f629, f=inhx32
#include <p12f629.inc>

__CONFIG _WDT_OFF&_INTRC_OSC_NOCLKOUT&_BODEN_ON&_CP_OFF&_PWRTE_ON



;COUNTER equ 0x21
;ANSEL equ 0x9F
cblock 0x20
d1
d2
endc
;**********************************************************************
ORG 0x000 ; processor reset vector
goto init ; go to beginning of program


ORG 0x004 ; interrupt vector location
init:
call 0x3FF ; retrieve factory calibration value
bsf STATUS,RP0 ; set file register bank to 1
movwf OSCCAL ; update register with factory cal value
bcf STATUS,RP0 ; set file register bank to 0
CLRF GPIO ;Init GPIO
MOVLW 07h ;Set GP<2:0> to
MOVWF CMCON ;digital IO
BSF STATUS,RP0 ;Bank 1
;CLRF ANSEL ;Digital I/O
MOVLW b'00011111' ;Sets inputs and outputs
MOVWF TRISIO ;and set outputs
BCF STATUS,RP0 ;Bank 0
;movlw 20h
;movwf GPIO
;movlw 02h
;movwf COUNTER
goto main
main:

call lowtest
;decfsz COUNTER,1
goto main

lowtest:
bsf GPIO,5
call Delay
bcf GPIO,5
call Delay
return

Delay:

movlw 0x97
movwf d1
movlw 0x09
movwf d2

Delay_0:
decfsz d1, f
goto $+2
decfsz d2, f
goto Delay_0
goto $+1
return
end
 
I used the above code and got the pulse but I want to be able to manually change the milliseconds inside the code itself so that I can change the on time and off time in milliseconds instead of using the delay loop I have used in my code right now.

I would really appreciate your help.

Thank you
 
The following delay sub-routine produces 1mS delay. Change the .1 (decimal one) to .44 for 44mS delay etc.

Code:
delay  movlw    .1
       movwf    mS_file
       nop
       decfsz    temp,f
       goto        $-2
       decfsz    mS_file,f
       goto       $-4        ;each loop = 1mS
       retlw      00
 
Last edited:
Thank you

It worked.

Thanks a lot

I am getting a stack underflow error when I want to display only three pulses.

The code works for continuous stream of pulses but not for specific number of pulses.

I have replaced the code for the delay with the one you suggested.
 
Following is my new code:

list p=12f629, f=inhx32
#include <p12f629.inc>

__CONFIG _WDT_OFF&_INTRC_OSC_NOCLKOUT&_BODEN_ON&_CP_OFF&_PWRTE_ON

COUNTER equ 0x21
COUNTER1 equ 0x22
temp equ 0x23
M1 equ 0x24
M2 equ 0x25
M3 equ 0x26
;ANSEL equ 0x9F
;cblock 0x20
;d1
; d2
;endc
;**********************************************************************
ORG 0x000 ; processor reset vector
goto init ; go to beginning of program


ORG 0x004 ; interrupt vector location
init:
call 0x3FF ; retrieve calibration value
bsf STATUS,RP0 ; set file register bank to 1
movwf OSCCAL ; update register with factory cal value
bcf STATUS,RP0 ; set file register bank to 0
CLRF GPIO ;Init GPIO
MOVLW 07h ;Set GP<2:0> to
MOVWF CMCON ;digital IO
BSF STATUS,RP0 ;Bank 1
;CLRF ANSEL ;Digital I/O
MOVLW b'00011111' ;Sets inputs and outputs
MOVWF TRISIO ;and set outputs
BCF STATUS,RP0 ;Bank 0
;movlw 20h
;movwf GPIO
;movlw 02h
;movwf COUNTER

;Variable definitions
;M1 on time of pulse
;M2 off time of pulse
;M3 number of pulses
;M4 on time of pulse
;M5 off time of pulse
;M6 number of pulses

movlw .10 ;on time of pulse #1
movwf M1
movlw .34 ;off time of pulse #1
movwf M2
movlw 02h ;number of pulse #1
movwf M3


main: decfsz M3,1
call lowtest
;decfsz M3,1
goto loop1

lowtest:
bsf GPIO,5
call Delay
bcf GPIO,5
call Delay1
return
;decfsz M3,1
;goto main
;goto loop1

Delay movf M1,0
movwf COUNTER
nop
decfsz temp,f
goto $-2
decfsz COUNTER,f
goto $-4
retlw 00


Delay1 movf M2,0
movwf COUNTER1
nop
decfsz temp,f
goto $-2
decfsz COUNTER1,f
goto $-4
retlw 00
loop1: ;nop
;goto $-2
end
 
I have to control the number of pulses to be displayed.
But the above code is not working.

I am getting the CORE-E0002 Stack underflow error.

Please let me know if anybody has an idea to solve this problem.

Thanks and Best Regards,
Vishal
 
Trace your calls and returns, somehow you are hitting a return without a matching call.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…