• AVR Freaks

Hot!PIC10F222 builds but not work as expected

Author
karka
New Member
  • Total Posts : 7
  • Reward points : 0
  • Joined: 2019/02/26 02:33:25
  • Location: 0
  • Status: offline
2019/04/09 04:19:49 (permalink)
0

PIC10F222 builds but not work as expected

Hello,

The problem is that the asm code builds, but not working as expected. Could anyone help me with this problem? Thank you for your time.

list p=10F222 ; list directive to define processor
#include p10F222.inc ; processor specific variable definitions

__CONFIG _MCLRE_ON&_CP_OFF&_WDT_OFF&_MCPU_OFF&_IOFSCS_4MHZ


;***** VARIABLE DEFINITIONS
TEMP_VAR UDATA
temp1 RES 1 ;DELAY REGISTER1
temp2 RES 1 ;DELAY REGISTER2
temp3 RES 1 ;DELAY REGISTER3
temp4 RES 1 ;DELAY REGISTER4
temp5 RES 1 ;TIMING REGISTER
temp6 RES 1 ;TINING REGISTER



;**********************************************************************
RESET_VECTOR CODE 0xFF ; processor reset vector

; Internal RC calibration value is placed at location 0xFF by Microchip
; as a movlw k, where the k is a literal value.

MAIN CODE 0x000
movwf OSCCAL ; update register with factory cal value


initialize:
movlw B'0010'
tris GPIO ; INITIALIZE
clrf ADCON0 ; ADC DISABLE
clrf GPIO
movlw b'00001000'
option ; ENABLE GPIO2 AS A DIGITAL PORT
clrf GPIO

START:

SCAN1:
btfss GPIO,1
goto SCAN1
ENSURE:
btfsc GPIO,1
goto ENSURE
call LOOP1
COUNTDOWN:
movlw 0xFF
movwf temp5
movlw 0xFF
movwf temp6
COUNTDOWN2:
btfsc GPIO,1
goto RELAYACTIVATE
decfsz temp5
goto COUNTDOWN2
movlw 0xFF
movwf temp5
decfsz temp6
goto COUNTDOWN2
goto SCAN1

RELAYACTIVATE:
bsf GPIO,0
call LOOP1
call LOOP1
call LOOP1
SCAN2:
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
reset
    
LOOP1:
movlw 0x00
movwf temp1
movlw 0xF0
movwf temp2

LOOP2:
decfsz temp1
goto LOOP2
decfsz temp2
goto LOOP2
RETLW 0


end




post edited by karka - 2019/04/10 07:00:27

Attached Image(s)

#1

16 Replies Related Threads

    jack@kksound
    code tags!
    • Total Posts : 3201
    • Reward points : 0
    • Joined: 2014/05/14 10:03:19
    • Location: 0
    • Status: offline
    Re: PIC10F222 builds but not work as expected 2019/04/09 09:07:32 (permalink)
    +1 (1)
    Maybe tell us a little more? What do you expect and what actually happens?
    #2
    NKurzman
    A Guy on the Net
    • Total Posts : 17599
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: offline
    Re: PIC10F222 builds but not work as expected 2019/04/09 10:08:55 (permalink)
    +1 (1)
     but not working as expected, by who? you?
    What do you expect?  What is actually happening?
    #3
    karka
    New Member
    • Total Posts : 7
    • Reward points : 0
    • Joined: 2019/02/26 02:33:25
    • Location: 0
    • Status: offline
    Re: PIC10F222 builds but not work as expected 2019/04/09 10:25:09 (permalink)
    0
    The whole code is working with the RELAY SWITCH. Please check the circuit I have attached.
     
    Microcontroller PinOut:
    Pin#2 = VCC (5v)
    Pin#4 = GPIO,1 (Programmed as an input)
    Pin#5 = GPIO,0 (Programmed as an output)
    Pin#7 = Ground 
     
    This project is about Clap ON/OFF process. I have already made a PCB and soldered whole circuit, but the relay is not working from the sound of clapping it works only when you put on and off cabel to the 230V socket. I have also tested with multimeter the microphone voltage which reacts to the sound and gives different voltages. I guess that it is microcontroller code fault, because when testing my PIN#5 OUTPUT with multimeter I do not get any voltage which should proceed to relay (check circuit).

    Thank you for your time
     
     
    #4
    coffee critic
    Super Member
    • Total Posts : 368
    • Reward points : 0
    • Status: offline
    Re: PIC10F222 builds but not work as expected 2019/04/09 10:38:31 (permalink)
    +1 (1)
    What is your voltage on MCLR?

    n_*$
    #5
    karka
    New Member
    • Total Posts : 7
    • Reward points : 0
    • Joined: 2019/02/26 02:33:25
    • Location: 0
    • Status: offline
    Re: PIC10F222 builds but not work as expected 2019/04/09 11:13:24 (permalink)
    0
    4,75V
    #6
    coffee critic
    Super Member
    • Total Posts : 368
    • Reward points : 0
    • Status: offline
    Re: PIC10F222 builds but not work as expected 2019/04/09 11:28:30 (permalink)
    0
    The DC gain on the first stage is ~100 and the GBW is 1MHz.  What is the frequency and amplitude of the impulse you get from the microphone?  Do you see this same on the output of stage 1?

    n_*$
    #7
    qhb
    Superb Member
    • Total Posts : 9998
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: offline
    Re: PIC10F222 builds but not work as expected 2019/04/09 13:21:59 (permalink)
    +1 (1)
    coffee critic
    What is your voltage on MCLR?


    karka
    4,75V

    Measured how?
    Your code says that this pin is enabled, and your schematic shows that nothing is connected to the pin, so it is floating.
    You should either add a pullup on this pin, or disable it in your CONFIG setting.
     

    Nearly there...
    #8
    karka
    New Member
    • Total Posts : 7
    • Reward points : 0
    • Joined: 2019/02/26 02:33:25
    • Location: 0
    • Status: offline
    Re: PIC10F222 builds but not work as expected 2019/04/09 13:24:05 (permalink)
    0
    Should I do MCLR OFF in my CONFIG settings?
    #9
    qhb
    Superb Member
    • Total Posts : 9998
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: offline
    Re: PIC10F222 builds but not work as expected 2019/04/09 13:26:22 (permalink)
    +1 (1)
    Yes, if you don't want to install a pullup resistor on your PCB.
     

    Nearly there...
    #10
    karka
    New Member
    • Total Posts : 7
    • Reward points : 0
    • Joined: 2019/02/26 02:33:25
    • Location: 0
    • Status: offline
    Re: PIC10F222 builds but not work as expected 2019/04/09 13:43:09 (permalink)
    0
    Thank you for your answer. Already changed, I will try to test it tomorrow and give the news. Do you think that was the problem?
    #11
    qhb
    Superb Member
    • Total Posts : 9998
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: offline
    Re: PIC10F222 builds but not work as expected 2019/04/09 13:45:56 (permalink)
    +3 (3)
    I could have been.
    You are making the classic beginner's mistake of depending upon everything working at once.
    It is more productive to start slowly. i.e. test ONLY that you can output something first, e.g. by slowly setting the output pin high and low over and over.
    Only when you know that is working correctly, add the code to test the input, then see if that works.
    Otherwise, if you  try to test everything at once, you don't know which bit is not working right.
     
     

    Nearly there...
    #12
    karka
    New Member
    • Total Posts : 7
    • Reward points : 0
    • Joined: 2019/02/26 02:33:25
    • Location: 0
    • Status: offline
    Re: PIC10F222 builds but not work as expected 2019/04/10 07:00:54 (permalink)
    0
    Hello, 

    These are results after I changed MCLR OFF. (attached photo voltage.jpg)
    #13
    qhb
    Superb Member
    • Total Posts : 9998
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: offline
    Re: PIC10F222 builds but not work as expected 2019/04/10 13:14:26 (permalink)
    0
    karka
    These are results after I changed MCLR OFF. (attached photo voltage.jpg)

    No photo attached.

    Nearly there...
    #14
    karka
    New Member
    • Total Posts : 7
    • Reward points : 0
    • Joined: 2019/02/26 02:33:25
    • Location: 0
    • Status: offline
    Re: PIC10F222 builds but not work as expected 2019/04/11 02:15:06 (permalink)
    0
    Hello, already solved the problem by creating a new C code which works with relay. Thank you for help
    #15
    EwenF
    Starting Member
    • Total Posts : 65
    • Reward points : 0
    • Joined: 2003/11/07 12:38:00
    • Location: New Zealand
    • Status: offline
    Re: PIC10F222 builds but not work as expected 2019/07/20 23:08:53 (permalink)
    0
    Just a suggestion: Be more careful with documentation
    The comment in the following 2 lines makes no sense as this is setting the PSA bit in OPTION REG
    movlw b'00001000'
    option ; ENABLE GPIO2 AS A DIGITAL PORT

    #16
    ric
    Super Member
    • Total Posts : 23185
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: PIC10F222 builds but not work as expected 2019/07/21 02:09:16 (permalink)
    0
    EwenF
    The comment in the following 2 lines makes no sense as this is setting the PSA bit in OPTION REG

    You are ignoring the bits that are being set to zero.
    It is changing T0CS from the default setting (1 => GP2 functions as T0CKI)
    to 0 (T0 clocked by Fosc/4, pin functions as GP2).
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #17
    Jump to:
    © 2019 APG vNext Commercial Version 4.5