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.

PIC10F222 Coding

Status
Not open for further replies.

ItsElliot

New Member
As a project I am creating a Clap on / Clap off switch for my computer however the tutorial I am following is designed to toggle a relay on and then off, and I would like to make it pulse after detecting a clap; Is there a way to modify the code or the output for this? I will include links to the guide and the code it uses a PIC10F222:

https://www.instructables.com/id/How-...tch-/?ALLSTEPS
https://www.electroniclessons.com/10F222TMPO.ASM

If I get this working, I have a friend who will 3D print a box that can fit in one of the 5.25" bays in the front of the computer and can link to pictures when it is finished.

Thanks,

Elliot
 
Is there a way to modify the code or the output for this?
Attached below is the asm listing:

Code:
MAIN  CODE  0x000
MOVWF  OSCCAL  ; update register with factory cal value


INITIALIZE
MOVLW B'0010'    ; GPIO1=COMPARATOR IN - GPIO0-RELAY ACTIVATE
TRIS GPIO            ; INITIALIZE
CLRF ADCON0    ; ADC DISABLE
CLRF GPIO  ; CLEAR OUTPUTS
MOVLW B'00001000'
OPTION        ; ENABLE GPIO2 AS A DIGITAL PORT

SCAN1:
BTFSS GPIO,1  ; CHECK TO SEE IF LOUD NOISE (CLAP IS DETECTED)
GOTO SCAN1  ; IF NOT, SCAN AGAIN (LOOP)
ENSURE:
BTFSC GPIO,1  ; HAS THE WAVEFORM GONE FROM HIGH TO LOW?
GOTO ENSURE  ; IF NOT, CHECK AGAIN (LOOP).  IF SO, GOTO NEXT INSTRUCTION
CALL LOOP1  ; DELAY
COUNTDOWN:  ; COUNTDOWN ROUTINE
MOVLW 0XFF  ; LOAD REFERENCE VALUE
MOVWF TEMP5  ; LOAD TIMING REGISTER#1 WITH REFERENCE VALUE ABOVE
MOVLW 0XFF  ; LOAD REFERENCE VALUE
MOVWF TEMP6    ; LOAD TIMING REGISTER#2 WITH REFERENCE VALUE
COUNTDOWN2:   ; ACTUAL DOUNTDOWN ROUTINE
BTFSC GPIO,1   ; CHECK TO SEE IF LOUD NOISE IS APPARENT.
GOTO RELAYACTIVATE    ; IF YES, ACTIVATE RELAY (TOGGLE)
DECFSZ TEMP5    ; IF NOT, DECREMENT COUNTER#1  IF REG=0, SKIP NEXT STEP
GOTO COUNTDOWN2      ; GO BACK AND LOOK AGAIN FOR SECOND LOUD NOISE
MOVLW 0XFF ; LOAD TIMING REGISTER#1 WITH FULL VALUE AGAIN
MOVWF TEMP5    ; LOAD
DECFSZ TEMP6  ; DECREMENT T-REGISTER#2
GOTO COUNTDOWN2   ; IF TIMING REGISTER#2 IS NOT Z, DO SECOND SCAN AGAIN
GOTO SCAN1          ; IF TIMING REGISTER#2 WAS 0, GO BACK TO START

RELAYACTIVATE:
BSF GPIO,0  ; ACTIVATE RELAY
CALL LOOP1  ; SERIES OF 3 DELAYS
CALL LOOP1
CALL LOOP1
; THIS NEXT SEQUENCE IS JUST A MIMICK OF THE FIRST SEQUENCE, ONLY WE ARE
; WAITING TO TOGGLE THE RELAY BACK TO ITS ORIGINAL POTISION.
; I HAVE ADDED IN A SHORT DELAY AT THE BEGINNING, DENOTED BY ***
SCAN2:
CALL LOOP1  ; ***  SERIES OF 3 DELAYS
CALL LOOP1
CALL LOOP1
BTFSS GPIO,1
GOTO SCAN2
ENSURE2:
BTFSC GPIO,1
GOTO ENSURE2
CALL LOOP1
COUNTDOWN3:
MOVLW 0XFF
MOVWF TEMP5
MOVLW 0XFF
MOVWF TEMP6
COUNTDOWN4:
BTFSC GPIO,1
GOTO RELAYDEACTIVATE
DECFSZ TEMP5
GOTO COUNTDOWN4
MOVLW 0XFF
MOVWF TEMP5
DECFSZ TEMP6
GOTO COUNTDOWN4
GOTO SCAN2

RELAYDEACTIVATE:
BCF GPIO,0  ; DEACTIVATE RELAY
RESET  ; RESET PROGRAM

LOOP1:
;THE LOOP ROUTINE WORKS LIKE THIS.  WE LOAD TIMING REGISTER TEMP1/2 WITH 8-BIT
VALUES, AND IT WORKS TO ESSENTIALLY COUNT DOWN THE FIRST REGISTER, AND
WHEN THE FIRST REGISTER IS 0, THE PROGRAM DECREMENTS THE SECOND TIMING REGISTER (TEMP2).  AT THIS POINT, THIS KEEPS ON DOING THE SAME THING UNTIL TEMP2 REGISTER VALUE = 0, AT WHICH POINT, THE DELAY ENDS, AND WE GO BACK TO THE PROGRAM.
MOVLW 0X00
MOVWF TEMP1
MOVLW 0XF0
MOVWF TEMP2

LOOP2:
DECFSZ TEMP1
GOTO LOOP2
DECFSZ TEMP2
GOTO LOOP2
RETURN

END

You will note that the section for the relay to be switched on is "RELAYACTIVATE".
Loop1 is then called three times.
Loop1 simply wastes a little bit of time.
Calling Loop1 multiple times just wastes more time.
The simplest way to make the output pulse, is to do a copy/paste within the "RELAYACTIVATE" section, with one minor change;
BSF GPIO,0 is the line which turns the relay on. BSF is Bit Set File and GPIO,0 is the pin which is manipulated.
To turn the output off for GPIO,0 BCF is used - Bit Clear File, which can be seen in the "RELAYDEACTIVATE" section.

You don't mention how many times you want the output to pulse and the frequency of the pulse, but to give you a quick idea, the following will pulse the GPIO,0 output 3 times.
RELAYACTIVATE:
BSF GPIO,0 ; ACTIVATE RELAY
CALL LOOP1 ; SERIES OF 3 DELAYS
CALL LOOP1
CALL LOOP1
BCF GPIO,0 ; DEACTIVATE RELAY
CALL LOOP1 ; SERIES OF 3 DELAYS
CALL LOOP1
CALL LOOP1
BSF GPIO,0 ; ACTIVATE RELAY
CALL LOOP1 ; SERIES OF 3 DELAYS
CALL LOOP1
CALL LOOP1
BCF GPIO,0 ; DEACTIVATE RELAY
CALL LOOP1 ; SERIES OF 3 DELAYS
CALL LOOP1
CALL LOOP1
BSF GPIO,0 ; ACTIVATE RELAY
CALL LOOP1 ; SERIES OF 3 DELAYS
CALL LOOP1
CALL LOOP1
BCF GPIO,0 ; DEACTIVATE RELAY
CALL LOOP1 ; SERIES OF 3 DELAYS
CALL LOOP1
CALL LOOP1

If the time between the output being on/off is too small, you can call Loop1 a few more times inbetween each change of state. If the time is too long, you can remove a Loop1 line or two.

Let us know the frequency and duration of the pulse you require, if the above is not suitable for your application.

Regards.
 
Status
Not open for further replies.

Latest threads

Back
Top