Sorry for posting this in the GCB forum. I'm not a very good BASIC programmer, but I'm a much, much worse Assembly language programmer. I readily admit to not having a clue. Unfortunately I'd like to modify a program for which I only have the .ASM source, I presume it was written in Assembly language by someone cleverer than me.
The idea seems to be that after a 'timeout' period, a fault is raised. An input (PORTB,5) provides indication of a Hopper fault. Once a fault has been raised the PIC enters a loop that is only cleared on power off/on.
I want to modify this such that if the 'Hopper' fault is cleared, so is the fault condition, but if the fault was raised by the 'timeout' condition, remain in the loop forever.
Here is a portion of the original code:
BTFSCPORTB,5;CHECK FAULT I/P FROM HOPPERGOTOFAULT;DRIVEDECFSZCOUNT,1;DECREMENT TIME LIMIT PERIOD.GOTOMOTOR;CONTINUE TO APPLY POWER.DECFSZMULT,1;DECREMENT TIME LIMIT MULTIPLIER.GOTOPRESETGOTOFAULT;IF MULTIPLIER REACHES ZERO THEN = FAULT.;; Other code here;FAULTBSFPORTA,1;SWITCH MOTOR DRIVE OFF. = HIGH.BSFPORTA,2;SET ALARM O/P HIGH TO INDICATE FAULT.CLRWDTGOTOFAULT;WAIT FOR ATTENDANT TO RESET MACHINE;;END
And here is my modified code for the FAULT routine:
FAULTBSFPORTA,1;SWITCH MOTOR DRIVE OFF. = HIGH.BSFPORTA,2;SET ALARM O/P HIGH TO INDICATE FAULT.CLRWDTMOVFMULT,F;If Sent From Hopper Check Still ExistsBTFSCSTATUS,Z;MULT=0, timeout. MULT>0, Hopper Fault.GOTOFAULT;WAIT FOR ATTENDANT TO RESET MACHINEBTFSCPORTB,5;CHECK FAULT I/P FROM HOPPERGOTOFAULT;If Hopper Fault Present, GOTO FAULTRETLW0;Otherwise, Return.;;END
Have I understood the flow of the program correctly in that the BTFSC PORTB,5 tests the status of PORTB5 and if set executes GOTO FAULT, otherwise executes the following line with the label DRIVE? That DECFSZ MULT,1 instruction decrements MULT by the parameter '1' and then if not set to zero executes the next instruction (GOTO PRESET) whereas if MULT is zero, skips GOTO PRESET and executes GOTO FAULT instead?
Assuming I have understood that much, would my modifications to the FAULT routine do as I expect?
I have attempted to test MULT to see if it is zero (which I would assume indicates a motor timeout condition has occurred) with the MOVF MULT,F and BTFSC STATUS,Z statements which if zero should loop around continuously, if this is not zero, I then re-test PORTB,5 to see if it is still set and either loop around again, or if the error has cleared, execute the RETURN.
Last edit: mkstevo 2017-09-01
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Unless you’re trying to implement this logic in GCB, it would seem that this question should go to one of the many PIC programming forums where hard-core ASM programmers hang out. Although a solution might kindly be suggested here, it’s of little value to the general GCB community.
From: mkstevo
Sent: Friday, September 01, 2017 10:34 AM
To: [gcbasic:discussion]
Subject: [gcbasic:discussion] Assembly programming
Sorry for posting this in the GCB forum. I'm not a very good BASIC programmer, but I'm a much, much worse Assembly language programmer. I readily admit to not having a clue. Unfortunately I'd like to modify a program for which I only have the .ASM source, I presume it was written in Assembly language by someone cleverer than me.
I'm trying to modify some existing code for which I only have the .ASM source.
The idea seems to be that after a 'timeout' period, a fault is raised. A second input provides indication of a Hopper fault. Once the fault has been raised the PIC enters a loop that is only cleared on power off/on.
I want to modify this such that if the 'Hopper' fault is cleared, so is the fault condition, but if the fault was raised by the 'timeout' condition, remain in the loop forever.
Here is a portion of the original code:
BTFSC PORTB,5 ;CHECK FAULT I/P FROM HOPPER
GOTO FAULT
;
DRIVE DECFSZ COUNT,1 ;DECREMENT TIME LIMIT PERIOD.
GOTO MOTOR ;CONTINUE TO APPLY POWER.
DECFSZ MULT,1 ;DECREMENT TIME LIMIT MULTIPLIER.
GOTO PRESET
GOTO FAULT ;IF MULTIPLIER REACHES ZERO THEN = FAULT.
;
; Other code here
;
FAULT BSF PORTA,1 ;SWITCH MOTOR DRIVE OFF. = HIGH.
BSF PORTA,2 ;SET ALARM O/P HIGH TO INDICATE FAULT.
CLRWDT
GOTO FAULT ;WAIT FOR ATTENDANT TO RESET MACHINE
;
;
END
And here is my modified code for the FAULT routine:
FAULT BSF PORTA,1 ;SWITCH MOTOR DRIVE OFF. = HIGH.
BSF PORTA,2 ;SET ALARM O/P HIGH TO INDICATE FAULT.
CLRWDT
MOVF MULT,F ;If Sent From Hopper Check Still Exists
BTFSC STATUS,Z ;MULT=0, timeout. MULT>0, Hopper Fault.
GOTO FAULT ;WAIT FOR ATTENDANT TO RESET MACHINE
BTFSC PORTB,5 ;CHECK FAULT I/P FROM HOPPER
GOTO FAULT ;If Hopper Fault Present, GOTO FAULT
RETLW 0 ;Otherwise, Return.
;
;
END
Have I understood the flow of the program correctly in that the BTFSC PORTB,5 tests the status of PORTB5 and if set executes GOTO FAULT, otherwise executes the following line with the label DRIVE? That DECFSZ MULT,1 instruction decrements MULT by the parameter '1' and then if not set to zero executes the next instruction (GOTO PRESET) whereas if MULT is zero, skips GOTO PRESET and executes GOTO FAULT instead?
Assuming I have understood that much, would my modifications to the FAULT routine do as I expect?
I have attempted to test MULT to see if it is zero (which I would assume indicates a motor timeout condition has occurred) with the MOVF MULT,F and BTFSC STATUS,Z statements which if zero should loop around continuously, if this is not zero, I then re-test PORTB,5 to see if it is still set and either loop around again, or if the error has cleared, execute the RETURN.
You are right Joe, perhaps this isn't the place. If it isn't, I'll be only too happy to delete my request.
I had understood that some of the really clever people here did have some knowledge of Assembly Programming as GCB does compile into .ASM and on occasions members have requested to look at these .ASM files in order to diagnose problems. However, relying on goodwill is possibly a little cheeky, for which I apologise again.
I would have posted my request on some other forum but I don't have any prescence on any Assembly Language forums, as I don't use, or understand Assembly Language.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I may be wrong but, judging by the code snippet you provided, it looks like you are attempting to override a safety feature that requires operator confirmation that the fault is cleared before restarting the hopper.
That fail safe code is there for a reason and probably required by the appropriate safety certification.
I doubt anyone will be willing to help you circumvent that, even on an ASM forum.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
No Chris, I'm not attempting to circumvent anything safety related.
The original code is designed such that should a motor become stuck, or gift not be paid (from a hopper) an error is permanently raised until such time as the error is cleared, requiring the machine to be switched off and on.
I have designed a replacement unit that will deliver a number of tickets as gifts, no longer requiring the hopper. My ticket dispensing unit raises an error should the required number of tickets not be paid out. However, my ticket dispenser has the facility that once it has been refilled with tickets, any remaining balance of unpaid tickets will be paid out, and the error cleared. Hence the reason I'd like to clear the machine error later if it was raised by the 'hopper'. No safety issues involved of any sort.
I want to retain the 'motor timeout' errors as these do indeed require the machine to be restarted, I just thought it would be more elegant for the ticket error to be cleared on completion, something the original designer did not have to consider.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Well, in order to close this out and complete my request, I did what (perhaps) I should have done in the first place. I wrote the following code in GCB:
#Chip16C55,4#ConfigWDT_ON#DefineHopperPortB.5#DefineMotor_ActPortA.1#DefineAlarmPortA.2DimMultAsByteDimCountAsByteDirHopperInDirMotor_StpOutDirAlarmOutLetCount=255LetMult=255DriveSubDriveLetCount=Count-1IfCount=0ThenLetMult=Mult-1IfMult=0ThenGoSubFaultEndIfEndIfIfHopper=1ThenGoSubFaultEndIfGoSubPresetEndSubSubPresetWait1mSEndSubSubFaultFLT:LetMotor_Stp=1LetAlarm=1CLRWDTIfMult=0Then'Fault sent from Motor TimeoutGotoFLT'Loop until Attendant Resets the MachineEndIfIfHopper=0Then'Hopper Fault ClearedReturn'Exit Fault RoutineEndIfGotoFLT'Loop until Attendant Resets the MachineEndSub
I then compiled it, and looked at the generated .ASM file, I have removed the GCB source file coments and am only showing the Fault routine:
This does look similar to that which I showed initially so I am more confident that my changes should work as I intended.
I apologise once more if my request was inappropriate for this forum and should a moderator wish to delete this thread I shan't be in the least offended.
Last edit: mkstevo 2017-09-03
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
"Sorry for posting this in the GCB forum. I'm not a very good BASIC programmer, but I'm a much, much worse Assembly language programmer. I readily admit to not having a clue."
Really? :)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You have now taken the path that I may have suggested. Write in GCB and insert the ASM into your existing program.
Going further, I would probably re-write the entire program in GCB (time permitting). But you have not told us what microcontroller chip you are using, and have not posted complete code. So we are in guess mode as to the complexity of the complete progran and the difficulty of converting it all to GCB.
Patching ASM can be tricky.
William
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'd normally try to rewrite the entire program (which isn't that large) but...
It is difficult for me to follow the flow and execution of an Assembly Program as it is and I don't want to try to decode the entire program. The main portion of the program itself provides a variable PWM drive for various motors that can be controlled through dip switches. This PWM is hard coded (as best I can tell) with routines for 'On' and 'Off' pulses which I can't really determine the timing of the PWM from. As the frequency of the PWM is rather critical I'd rather not mess about with this if I don't have to.
My addition of an exit route for a 'soft' error is something which would be satisfying for me to have, but isn't critical. If I can add it, I'd like to, if I can't, so be it.
I'll try to change the fault routine as I've indicated above. Should this not work as I hope I'll be miffed but not distraught.
Last edit: mkstevo 2017-09-04
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Sorry for posting this in the GCB forum. I'm not a very good BASIC programmer, but I'm a much, much worse Assembly language programmer. I readily admit to not having a clue. Unfortunately I'd like to modify a program for which I only have the .ASM source, I presume it was written in Assembly language by someone cleverer than me.
The idea seems to be that after a 'timeout' period, a fault is raised. An input (PORTB,5) provides indication of a Hopper fault. Once a fault has been raised the PIC enters a loop that is only cleared on power off/on.
I want to modify this such that if the 'Hopper' fault is cleared, so is the fault condition, but if the fault was raised by the 'timeout' condition, remain in the loop forever.
Here is a portion of the original code:
And here is my modified code for the FAULT routine:
Have I understood the flow of the program correctly in that the BTFSC PORTB,5 tests the status of PORTB5 and if set executes GOTO FAULT, otherwise executes the following line with the label DRIVE? That DECFSZ MULT,1 instruction decrements MULT by the parameter '1' and then if not set to zero executes the next instruction (GOTO PRESET) whereas if MULT is zero, skips GOTO PRESET and executes GOTO FAULT instead?
Assuming I have understood that much, would my modifications to the FAULT routine do as I expect?
I have attempted to test MULT to see if it is zero (which I would assume indicates a motor timeout condition has occurred) with the MOVF MULT,F and BTFSC STATUS,Z statements which if zero should loop around continuously, if this is not zero, I then re-test PORTB,5 to see if it is still set and either loop around again, or if the error has cleared, execute the RETURN.
Last edit: mkstevo 2017-09-01
Unless you’re trying to implement this logic in GCB, it would seem that this question should go to one of the many PIC programming forums where hard-core ASM programmers hang out. Although a solution might kindly be suggested here, it’s of little value to the general GCB community.
From: mkstevo
Sent: Friday, September 01, 2017 10:34 AM
To: [gcbasic:discussion]
Subject: [gcbasic:discussion] Assembly programming
Sorry for posting this in the GCB forum. I'm not a very good BASIC programmer, but I'm a much, much worse Assembly language programmer. I readily admit to not having a clue. Unfortunately I'd like to modify a program for which I only have the .ASM source, I presume it was written in Assembly language by someone cleverer than me.
I'm trying to modify some existing code for which I only have the .ASM source.
The idea seems to be that after a 'timeout' period, a fault is raised. A second input provides indication of a Hopper fault. Once the fault has been raised the PIC enters a loop that is only cleared on power off/on.
I want to modify this such that if the 'Hopper' fault is cleared, so is the fault condition, but if the fault was raised by the 'timeout' condition, remain in the loop forever.
Here is a portion of the original code:
;
DRIVE DECFSZ COUNT,1 ;DECREMENT TIME LIMIT PERIOD.
GOTO MOTOR ;CONTINUE TO APPLY POWER.
DECFSZ MULT,1 ;DECREMENT TIME LIMIT MULTIPLIER.
GOTO PRESET
GOTO FAULT ;IF MULTIPLIER REACHES ZERO THEN = FAULT.
;
; Other code here
;
FAULT BSF PORTA,1 ;SWITCH MOTOR DRIVE OFF. = HIGH.
BSF PORTA,2 ;SET ALARM O/P HIGH TO INDICATE FAULT.
CLRWDT
GOTO FAULT ;WAIT FOR ATTENDANT TO RESET MACHINE
;
;
END
And here is my modified code for the FAULT routine:
FAULT BSF PORTA,1 ;SWITCH MOTOR DRIVE OFF. = HIGH.
BSF PORTA,2 ;SET ALARM O/P HIGH TO INDICATE FAULT.
CLRWDT
MOVF MULT,F ;If Sent From Hopper Check Still Exists
BTFSC STATUS,Z ;MULT=0, timeout. MULT>0, Hopper Fault.
GOTO FAULT ;WAIT FOR ATTENDANT TO RESET MACHINE
BTFSC PORTB,5 ;CHECK FAULT I/P FROM HOPPER
GOTO FAULT ;If Hopper Fault Present, GOTO FAULT
RETLW 0 ;Otherwise, Return.
;
;
END
Have I understood the flow of the program correctly in that the BTFSC PORTB,5 tests the status of PORTB5 and if set executes GOTO FAULT, otherwise executes the following line with the label DRIVE? That DECFSZ MULT,1 instruction decrements MULT by the parameter '1' and then if not set to zero executes the next instruction (GOTO PRESET) whereas if MULT is zero, skips GOTO PRESET and executes GOTO FAULT instead?
Assuming I have understood that much, would my modifications to the FAULT routine do as I expect?
I have attempted to test MULT to see if it is zero (which I would assume indicates a motor timeout condition has occurred) with the MOVF MULT,F and BTFSC STATUS,Z statements which if zero should loop around continuously, if this is not zero, I then re-test PORTB,5 to see if it is still set and either loop around again, or if the error has cleared, execute the RETURN.
Assembly programming
Sent from sourceforge.net because you indicated interest in https://sourceforge.net/p/gcbasic/discussion/579125/
To unsubscribe from further messages, please visit https://sourceforge.net/auth/subscriptions/
You are right Joe, perhaps this isn't the place. If it isn't, I'll be only too happy to delete my request.
I had understood that some of the really clever people here did have some knowledge of Assembly Programming as GCB does compile into .ASM and on occasions members have requested to look at these .ASM files in order to diagnose problems. However, relying on goodwill is possibly a little cheeky, for which I apologise again.
I would have posted my request on some other forum but I don't have any prescence on any Assembly Language forums, as I don't use, or understand Assembly Language.
I may be wrong but, judging by the code snippet you provided, it looks like you are attempting to override a safety feature that requires operator confirmation that the fault is cleared before restarting the hopper.
That fail safe code is there for a reason and probably required by the appropriate safety certification.
I doubt anyone will be willing to help you circumvent that, even on an ASM forum.
No Chris, I'm not attempting to circumvent anything safety related.
The original code is designed such that should a motor become stuck, or gift not be paid (from a hopper) an error is permanently raised until such time as the error is cleared, requiring the machine to be switched off and on.
I have designed a replacement unit that will deliver a number of tickets as gifts, no longer requiring the hopper. My ticket dispensing unit raises an error should the required number of tickets not be paid out. However, my ticket dispenser has the facility that once it has been refilled with tickets, any remaining balance of unpaid tickets will be paid out, and the error cleared. Hence the reason I'd like to clear the machine error later if it was raised by the 'hopper'. No safety issues involved of any sort.
I want to retain the 'motor timeout' errors as these do indeed require the machine to be restarted, I just thought it would be more elegant for the ticket error to be cleared on completion, something the original designer did not have to consider.
Well, in order to close this out and complete my request, I did what (perhaps) I should have done in the first place. I wrote the following code in GCB:
I then compiled it, and looked at the generated .ASM file, I have removed the GCB source file coments and am only showing the Fault routine:
This does look similar to that which I showed initially so I am more confident that my changes should work as I intended.
I apologise once more if my request was inappropriate for this forum and should a moderator wish to delete this thread I shan't be in the least offended.
Last edit: mkstevo 2017-09-03
"Sorry for posting this in the GCB forum. I'm not a very good BASIC programmer, but I'm a much, much worse Assembly language programmer. I readily admit to not having a clue."
Really? :)
Ha! That was my reaction too!
Cheers,
Chris S.
@mkstevo
You have now taken the path that I may have suggested. Write in GCB and insert the ASM into your existing program.
Going further, I would probably re-write the entire program in GCB (time permitting). But you have not told us what microcontroller chip you are using, and have not posted complete code. So we are in guess mode as to the complexity of the complete progran and the difficulty of converting it all to GCB.
Patching ASM can be tricky.
William
I'd normally try to rewrite the entire program (which isn't that large) but...
It is difficult for me to follow the flow and execution of an Assembly Program as it is and I don't want to try to decode the entire program. The main portion of the program itself provides a variable PWM drive for various motors that can be controlled through dip switches. This PWM is hard coded (as best I can tell) with routines for 'On' and 'Off' pulses which I can't really determine the timing of the PWM from. As the frequency of the PWM is rather critical I'd rather not mess about with this if I don't have to.
My addition of an exit route for a 'soft' error is something which would be satisfying for me to have, but isn't critical. If I can add it, I'd like to, if I can't, so be it.
I'll try to change the fault routine as I've indicated above. Should this not work as I hope I'll be miffed but not distraught.
Last edit: mkstevo 2017-09-04