PIC10F222 asm code builds, but not works as expected

Thread Starter

karka317

Joined Feb 26, 2019
18
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.

Pin#2 = VCC (5v)
Pin#4 = GPIO,1 (Programmed as an input)
Pin#5 = GPIO,0 (Programmed as an output) Here I do not get any signs of voltage when testing output
Pin#7 = Ground

Code:
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
 

Attachments

Raymond Genovese

Joined Mar 5, 2016
1,653
Hi @karka317

I am willing to try to help, but I have a bit of a problem that you first may be able to help with...

Back in this thread https://forum.allaboutcircuits.com/...ogram-device-please-help.157204/#post-1361213 you had problems programming the chip. We were able to get that issue sorted out. But, here is my problem...Back in this thread at another site https://electronics.stackexchange.c...ic10f222-failed-to-program-device-please-help you asked for help with that very same problem. The issue I have is that, while you found a solution, you did not bother to go back and reveal that solution in the other thread - even though a user (not me) specifically asked you to post the result.

Here and now, you have also posted the problem to multiple sites. Will you also not bother to go back to those sites and post a solution, should you find one?

I believe that this is a problem because 1) If I spend my time to help, I want to know whether or not it was successful and 2) even if it is unsuccessful, I want to know what the solution was - and so do other people who are looking for a similar solution.

What do you think?
 

jpanhalt

Joined Jan 18, 2008
11,087
Hi karka,

Your program does simulate with a few glitches.

1) I added destinations for the various decfsz tempX registers, but that probably doesn't make a difference. It just gets rid of warnings.
2) I don't believe "reset" (line 95) is an allowed instruction for that device.
3) With stimulus on GPIO,1 (4 cycles high) you can get through the program, but you have to toggle it twice to get to "RELAYACTUVATE." GPIO,0 does set.
4) The program never got to RELAYDEACTIVATE (line 94). At least for the little time played with it.
5) Your 10K base resistor seems a bit high for driving a relay, but again, you should still be able to measure a voltage at the pin when it goes high.
6) For trouble shooting, you might want to consider an LED and series resistor to ground to eliminate the relay for the time being. I would also edit out the need to press the button twice. That is, on start, it will idle at SCAN1 and ENSURE until released, then the RELAY/LED should light.

I did not spend much time with it, though.

Code:
     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



;**********************************************************************
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.

     CODE 0x000
     goto Main
Main
     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,f
     goto COUNTDOWN2
     movlw 0xFF
     movwf temp5
     decfsz temp6,f
     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,f
     goto COUNTDOWN4
     movlw 0xFF
     movwf temp5
     decfsz temp6,f
     goto COUNTDOWN4
     goto SCAN2

RELAYDEACTIVATE:
     bcf GPIO,0
reset
    
LOOP1:
     movlw 0x00
     movwf temp1
     movlw 0xF0
     movwf temp2

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


     end
 

Raymond Genovese

Joined Mar 5, 2016
1,653
Hi karka,

Your program does simulate with a few glitches.

1) I added destinations for the various decfsz tempX registers, but that probably doesn't make a difference. It just gets rid of warnings.
2) I don't believe "reset" (line 95) is an allowed instruction for that device.
3) With stimulus on GPIO,1 (4 cycles high) you can get through the program, but you have to toggle it twice to get to "RELAYACTUVATE." GPIO,0 does set.
4) The program never got to RELAYDEACTIVATE (line 94). At least for the little time played with it.
5) Your 10K base resistor seems a bit high for driving a relay, but again, you should still be able to measure a voltage at the pin when it goes high.
6) For trouble shooting, you might want to consider an LED and series resistor to ground to eliminate the relay for the time being. I would also edit out the need to press the button twice. That is, on start, it will idle at SCAN1 and ENSURE until released, then the RELAY/LED should light.

I did not spend much time with it, though.

Code:
     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



;**********************************************************************
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.

     CODE 0x000
     goto Main
Main
     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,f
     goto COUNTDOWN2
     movlw 0xFF
     movwf temp5
     decfsz temp6,f
     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,f
     goto COUNTDOWN4
     movlw 0xFF
     movwf temp5
     decfsz temp6,f
     goto COUNTDOWN4
     goto SCAN2

RELAYDEACTIVATE:
     bcf GPIO,0
reset
  
LOOP1:
     movlw 0x00
     movwf temp1
     movlw 0xF0
     movwf temp2

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


     end
@jpanhalt I was trying to make a point and I thought it was one that you have also made before. For example,

2) I don't believe "reset" (line 95) is an allowed instruction for that device.
Yes, you right and the OP asked about that here https://electronics.stackexchange.c...d-return-command-on-pic10f222-microcontroller and it was answered for him (including RETLW 0 discussion). It was also requested that he learn to comment the code. He did not respond to the people who had taken the time to respond and to do so in a helpful manner.

Now, a couple of months later, same OP, same project, same code, same return, same lack of code comments. You get what I am saying, or am I being too harsh?
 

Thread Starter

karka317

Joined Feb 26, 2019
18
Hello Raymond Genovese,

Thank you for your answer. Yes, I am sorry for posting many threads in different websites, because I am stuck in this process for 5-4 months. This is my 4 year work for bachelor degree in the university and I have 3 weeks to finish it, before facing the commission which will check my work and decide to pass me or not. Everything I do at the moment is a sleep, eat, electronics and repeat.

Jpanhalt thank you for your answer, I do not know the problem, because code seems fine, maybe it is because the new MPLAB IDE 5.15 version, I could able to try program it on MPLAB 8.92 old version in university. Or should I do code with C language to work, do not know...
 

jpanhalt

Joined Jan 18, 2008
11,087
@Raymond Genovese

Sorry, I did not see your post. I started looking at the code a bit more than 2 hours ago and was flipping back and forth between the More Options page and the project I set up for the code.
 

Raymond Genovese

Joined Mar 5, 2016
1,653
@Raymond Genovese

Sorry, I did not see your post. I started looking at the code a bit more than 2 hours ago and was flipping back and forth between the More Options page and the project I set up for the code.
n/p at all - I only responded because I read a recent post of yours on the general subject and agreed completely.

I have no idea if I have driven the OP away, I hope not, and I know there are lots of people who would like to help, including me - but I do wish students (of all levels) could realize a few things about this media.
 

jpanhalt

Joined Jan 18, 2008
11,087
Well, since his deadline is now just 3 weeks away, maybe he will be more interested in getting the code working. :)

And yes, my post about feedback had nothing to do with "likes." It had only to do with letting the "helpers" know whether there was success. As for running people off, "one and done" is pretty common among those who don't give feedback. I don't see that a short , automated follow-up (by PM as Ian suggested) will do any harm. If that thought gets any traction, it would be no problem coming up with a very few questions (less than 4) that would take less time than it took me to type this sentence.
 

Raymond Genovese

Joined Mar 5, 2016
1,653
Hello Raymond Genovese,

Thank you for your answer. Yes, I am sorry for posting many threads in different websites, because I am stuck in this process for 5-4 months. This is my 4 year work for bachelor degree in the university and I have 3 weeks to finish it, before facing the commission which will check my work and decide to pass me or not. Everything I do at the moment is a sleep, eat, electronics and repeat.

Jpanhalt thank you for your answer, I do not know the problem, because code seems fine, maybe it is because the new MPLAB IDE 5.15 version, I could able to try program it on MPLAB 8.92 old version in university. Or should I do code with C language to work, do not know...
I am not going to lecture you on the first part of your quoted post above, but I will say that it would have carried more weight had you gone and posted a response to the other threads first.

As for your current problem....

Would you care to explain clearly what the program is supposed to do and what it is doing?
What have you done to debug it?
Have you thought about what short bits of code that you could insert that would tell you something like..it made it this far?

When you say:
Pin#5 = GPIO,0 (Programmed as an output) Here I do not get any signs of voltage when testing output
Would you consider writing a small program that ONLY configures the chip and toggles GPIO 0 at an interval so that you can isolate whether you can get that far?

I think that you are less than 8 hours away from having code that runs and might do what you want, but you have to have a little better approach to debugging.
 

JohnInTX

Joined Jun 26, 2012
4,787
One possible problem is that MCLR/ is enabled in the CONFIG bits but not pulled up on the schematic.
My experience with 10F is that they can be more sensitive to r-m-w port problems than some others but try that LED on the output first.

I agree with the others, the way to fix stuff like this is to stick with a plan that tests various steps in your design. Running around to multiple sites, changing to C etc. is a recipe for failure.

Are you using a debug header (AC162070) and PICkit?
EDIT: corrected debug header p/n
 
Last edited:
One possible problem is that MCLR/ is enabled in the CONFIG bits but not pulled up on the schematic.
My experience with 10F is that they can be more sensitive to r-m-w port problems than some others but try that LED on the output first.
I think you might have just provided the OP with 8 hours of sleep :) I did look through the config__ line and read right through that!
 

Thread Starter

karka317

Joined Feb 26, 2019
18
Thank you for your answers.

I have spent a lot of time to this project asking for help colleagues and lecturers. Yes, I have tried many different things to solve the problem, but the seriously ones why my project do not work I have excluded as wrong Pot CT-94(101), I have changed to CT-94(104), but nothing happened and microcontroller ASM code problem not giving any signal in my PIN#5 OUTPUT. Also I have tried to create some similar codes in C language which would work with relay and put to my PIC, but unsuccessfully nothing happened due to my bad code or other reason. Do you know any examples in C language which could work in my situation?

Yes, I am using PICKIT 3 and ICD2 adapter to progam my PIC10F222.
I remember I have tried choosing this debug header AC162070 when I created a new Project in MPLAB X IDE 5.15, but nothing happened, I have tried many things different can't even remeber them all. Yes, I had thought about testing code with LED, I will try it.
 

Thread Starter

karka317

Joined Feb 26, 2019
18
I have left my work in the university with the PICKIT3 and it is closed at the moment, I will do it as soon as I can in the morning when I will arrive to the university and give you the news! Thank you for your time!
 

JohnInTX

Joined Jun 26, 2012
4,787
2) I don't believe "reset" (line 95) is an allowed instruction for that device.
It isn't of course. The assembler takes it as a LABEL and the code just drops through to LOOP1, which ends in a RETLW, which will underflow the stack *boom*. Maybe the code should GOTO the top where the 'reset' is?
 

JohnInTX

Joined Jun 26, 2012
4,787
Yes, I am using PICKIT 3 and ICD2 adapter to progam my PIC10F222.
I remember I have tried choosing this debug header AC162070 when I created a new Project in MPLAB X IDE 5.15, but nothing happened, I have tried many things different can't even remeber them all. Yes, I had thought about testing code with LED, I will try it.
First, get the debugger working:
  • Right Click the project name in the Projects window and click Properties.
  • Select AC162070 in the Supported Debug Header drop down.
  • Select PICkit3
  • Connect it all up. Install the Debug Header using the DIP-8 package pinout.
  • Open the source assembler file and click in the left-hand margin on the instruction after the label 'initialize:' to set a breakpoint.
  • Click Debug Main Project on the MPLABX toolbar. The project will build and the code will be loaded to the debug header.
  • Execution will start automatically and will stop at the breakpoint you set.
  • If it doesn't get there, FIX YOUR DEBUG ENVIRONMENT before proceeding. Don't try debugging without the header. The 10F has no native debugging and just programming the chip and wondering why it doesn't work (program and pray method) is not a good way to do it.

Once the debugger is working and stopped at initialize, step through the code by clicking the orange arrows in the debug toolbar.
  • Set a breakpoint on RELAYACTIVATE
  • Click RUN in the debug toolbar.
  • Operate your button.
  • If the code does not break there, go up the program steps setting breakpoints until you get one.
  • Step the code from there to see where your logic breaks down.
  • You can bypass the loop1 delay by right-clicking on the RETLW instruction then selecting RunToHere. For that subroutine you can also click 'Step Out' on the debugger toolbar. That will run the code until it hits a 'RETLW' instruction

Don't forget to replace 'reset' with a GOTO somewhere..

Good luck!
BTW: if you are using the 10F322 in a SOT23-6 package soldered to Microchip's SOT23 to 8pin DIP adapter you should know that the resulting pinout does NOT match the regular DIP8 chip. You'll have to buzz it out to see how it connects up.

EDIT: I flowed out your code for you. You should always do that BEFORE you code anything. When you do, it validates your logic or exposes errors in your thinking. Things like what happens after turning the relay OFF jump right out. When you are happy with your flow chart, just code each symbol and your code will work.
 

Attachments

Last edited:
It isn't of course. The assembler takes it as a LABEL and the code just drops through to LOOP1, which ends in a RETLW, which will underflow the stack *boom*. Maybe the code should GOTO the top where the 'reset' is?
I think that the version of mpasm that he is using will replace 'reset' with a retlw 0 and issue a warning:
Warning[227] xxx.ASM 104 : Substituting RETLW 0 for RETURN pseudo-op.

It can also issue warning for directives outside of col 1, but once the substitution is made, that gets rectified.

Since he does have a call, I think a retlw 0 is fine unless I am missing something.

It seems to me that one possibility is that with MCLR enabled and unconnected, he is in a continual state of reset. I don't know if that chip has any kind of internal pullup and seems possible that it is happening. In which case, he might never see a voltage on that pin.
 
Top