PIC10F222 asm code builds, but not works as expected

JohnInTX

Joined Jun 26, 2012
4,787
Some of the comments refer to using an 18F series chip. I am more inclined just to pass it off as Instructable plagiarism.

While I can't imagine anyone submitting this work as his own, perhaps moving it to Homework and requiring the TS to solve the "second event" issue for a chip without interrupts per se would at least show some contribution by him for getting a baccalaureate degree in engineering. I know what I would do, let's see if he understands the code himself to do that (without posting elsewhere for the answer) or something even better.
Instructable plagiarism. Funny. But it got me thinking and searching and lo and behold, you are correct, sir!

From 2012
https://www.edaboard.com/showthread...to-convert-follwing-assembly-code-to-hex-file

These are probably the original one - uses the ADC to sense the clap level.
http://www.electroniclessons.com/COMMENTED CLAP.txt
http://www.bradsprojects.com/forum/viewtopic.php?t=661

The first link even has the original RESET bug.
Geeze...

EDIT: Musing on this further, the edaboard code looks like a knockoff of the electronicslessons code by Patrick Mitchell. That code uses the PIC ADC to look for a very small change in voltage from the amplified microphone. Without the ADC, the clap detector has to swing full logic levels.

And here is Patrick Mitchell's Instructable with the same defective 'reset' code - line for line:
https://www.instructables.com/id/How-to-make-a-Clap-Clap-on-Clap-Clap-Off-switch-/
http://www.electroniclessons.com/10F222TMPO.ASM
That one uses a section of the LM324 as a comparator so maybe logic level input works. As for 'reset', he does mention an 18F. Maybe he prototyped it with that and left the 'reset' instruction to goto the top of the loop. Sorry stuff.

For the TS, that's the problem when you copy stuff from the internet. You actually have to understand it to use it and that comes from creating it - especially for a university project leading to a degree.

At any rate, I'm out.
Good luck!
 
Last edited:

jpanhalt

Joined Jan 18, 2008
11,087
While it is tempting and justifiable to cut the TS loose, if the TS will write his own code and focus on toggling a switch with a double clap while avoiding false signals from single claps, I would certainly be willing to help him. Moreover, I think it can be done with very little code. That is, assuming he has a reliable input from the microphone.

As first steps, he needs to define what is a double clap (i.e., the critical timings) and to show that the analog part of the circuit works to produce logic level changes on the 10F222 input. It is sad to see someone waste so many months when that time could have been used to learn something.
 

Thread Starter

karka317

Joined Feb 26, 2019
18
Hello,

I have already tested ASM code on PCB, but it still was not working, so with colleague we decided to rewrite the loop section, because as debugger shows it stops right before that section. After making these changes, the ASM code started giving 5V on PIN#5 and worked with the relay ON/OFF by double clapping, but there was problem with the delay. It turns ON and OFF in about 2sec delay, do not know why. I have also wrote a C code which work with the relay, it is much more simpler and took less lines than ASM code. I think I am going to stick with the C code, because I also want to add some additional functions to my PCB like adding bluetooth module or getting data from microcontroller. Thank you for helping to solve the problem!
 

BobaMosfet

Joined Jul 1, 2009
2,211
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...
Do you know what a flow-chart is? Understand what each instruction actually does, and then accurately create a flow-chart representing your code. You'll find your error quickly.
 

BobaMosfet

Joined Jul 1, 2009
2,211
@jpanhalt Yeah, you’re probably right. I was getting grumpy at the prospect that we might be wasting our time here. But yes, let’s see how it goes.
Thanks.
I disagree. I think your frustration is warranted. If someone has spent months on a problem like this, they simply aren't using the tools available to them (like flowcharting) to resolve the problem (and an accurate understanding of their mnemonics).
 

BobaMosfet

Joined Jul 1, 2009
2,211
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
The other reason you should be providing a flowchart is so that others can see the logic of your program (what are you trying to do?), instead of expecting them to derive it from reviewing your buggy code.
 
Top