Author Topic: Assembly code Help! PIC16F57  (Read 16037 times)

0 Members and 2 Guests are viewing this topic.

Offline KL27x

  • Super Contributor
  • ***
  • Posts: 4108
  • Country: us
Re: Assembly code Help! PIC16F57
« Reply #50 on: September 30, 2018, 07:53:01 pm »
Oh, haha.

I was made at least one edit to my forum post but didn't do it to the code, lol.

Try this one.

Also
reel_speed   equ   1F
slowdown_time   equ   20
reel2_trigger   equ   20
reel1_trigger   equ   50
reel0_trigger   equ   80

Also to note: For testing purposes you might want to mess with the values of these constants. So that the thing goes faster, for debugging/validating.
 

Offline KL27x

  • Super Contributor
  • ***
  • Posts: 4108
  • Country: us
Re: Assembly code Help! PIC16F57
« Reply #51 on: September 30, 2018, 08:33:18 pm »
source

Yeah, that would easier to try if I had attached the source code, sorry.
« Last Edit: September 30, 2018, 08:34:59 pm by KL27x »
 

Offline ElectrofinnTopic starter

  • Regular Contributor
  • *
  • Posts: 83
  • Country: gb
Re: Assembly code Help! PIC16F57
« Reply #52 on: September 30, 2018, 08:50:43 pm »
hahah ok, no worries dude. will report back.
 

Offline ElectrofinnTopic starter

  • Regular Contributor
  • *
  • Posts: 83
  • Country: gb
Re: Assembly code Help! PIC16F57
« Reply #53 on: September 30, 2018, 09:09:22 pm »
ok did it again so now i'm testing with new_byte set to 0F, light show is fine on your version btw
 

Offline ElectrofinnTopic starter

  • Regular Contributor
  • *
  • Posts: 83
  • Country: gb
Re: Assembly code Help! PIC16F57
« Reply #54 on: September 30, 2018, 09:34:44 pm »
if this still doesn't work I am almost tempted to call it a day on this particular problem because its not as if its that bad because it happens once in a blue moon and it at least does run the correct table even though it does half it doesn't really take too much away from the aesthetic of the game. if it payed out half the money I'd be like yeah this needs sorting but it's fine and I got the 32 value light show I wanted which is fantastic.


The only other problem is just when the machine gives the option to hold reels when you put the first credit in, which normally wouldn't be a problem for most of the session but when you first switch machine on, the displays default to all bars, which is part of the aesthetic but simply just holding all reels and pressing start gives an instant jackpot win. it doesn't seem to do this on the original chip. I think the hold option is a suppose to be a randomly generated thing for the most part but not sure because the source code seems to let this happen at the start without fail.

any ideas on that one?


**update** ok just had instance where a win did part of the "pattern" table, am switching back to new_byte equ 0E for now. although if it were someone else other than me playing the machine you probably wouldn't of noticed it to be honest.             
« Last Edit: October 01, 2018, 12:19:18 am by Electrofinn »
 

Offline KL27x

  • Super Contributor
  • ***
  • Posts: 4108
  • Country: us
Re: Assembly code Help! PIC16F57
« Reply #55 on: September 30, 2018, 09:49:51 pm »
So the most important thing for me to know at this point is what if any of these issues are present in the original source code you provided vs the updated version.

The fact the creator didn't find the production version of the code and gave you this one makes me wonder if some/all of these problems might be due to this version of code he gave to you.

Did you test the code you originally uploaded in the same way?

Here is my guess where the issues originate at this point, but your clarification on testing of the original code would be immensely helpful.

1. problems in original code                                     59%
2. problems in intended changes                               1%  ; highly confident
3. problems in my execution of intended changes       30% ; you never really know when coding in assembly
4. register 0E and 0F perhaps utilized by the code      10% ;  this is a bit weird if these problems are exactly the same when you tried both registers.

If you can verify that the code as you uploaded it to me is not producing any of these problems, I am still curious to see this a bit further.

 

Offline ElectrofinnTopic starter

  • Regular Contributor
  • *
  • Posts: 83
  • Country: gb
Re: Assembly code Help! PIC16F57
« Reply #56 on: September 30, 2018, 09:59:54 pm »
so just to clarify I am testing the completely untouched version straight from owner. will report back.
 

Offline ElectrofinnTopic starter

  • Regular Contributor
  • *
  • Posts: 83
  • Country: gb
Re: Assembly code Help! PIC16F57
« Reply #57 on: September 30, 2018, 10:08:42 pm »
ok just noticed something that may or may not have affected testing. just flashed device and its like it didn't take completely, first its like there was no change from last flashed code, then did it again and light show didn't show up and then decided to erase and blank check device and i then re-flashed and now I am back to original untouched code, as intended. up until now I had just been clicking program device without erasing, I forgot that mplab v8 doesn't erase device before re-program or does it?   
 

Offline ElectrofinnTopic starter

  • Regular Contributor
  • *
  • Posts: 83
  • Country: gb
Re: Assembly code Help! PIC16F57
« Reply #58 on: September 30, 2018, 10:44:57 pm »
Well it looks like this falls within your 59% or should that of been 69%..anyway it gave me 2 instances of an incorrect win light show. you were absolutely on the right track, good call, I just never noticed it before, just the obvious things.
« Last Edit: October 01, 2018, 12:18:12 am by Electrofinn »
 
The following users thanked this post: KL27x

Offline KL27x

  • Super Contributor
  • ***
  • Posts: 4108
  • Country: us
Re: Assembly code Help! PIC16F57
« Reply #59 on: October 01, 2018, 12:23:01 am »
 ;D ;D ;D ;D
I'm sorry, but I'm so so happy to hear this.

I have learned quite a bit, though. And if you ever do manage to figure out the general location or memory or something more specific about the issues, try and reach back. It's just quite hard for me to debug without the hardware in front of me.


I have learned (or relearned) a bunch of things though.
It would appear that baseline takes 3 instructions to do a long call and 2 for a pagesel. Midrange, indeed, is just 2 and 1. This is actually a much bigger limitation than the half page thing, IMO. This could take up more than half the code space of the program loop.

To get around the half page, all you should need to do is put your "Subroutine" as one instruction that is "goto subroutine.1" which is located in the upper half of the same page. :)

My partially modified source code page attached. I cleaned out the program loop to make it more legible. And moved the initialization to page 3. And if it works, that would be nice to know. But you might want to check out the main program loop and see how it looks now.

When I have trouble locating a bug in my own code, part of the "healing process" is to reformat/tab and generally clean things up. OP you might learn enough to actually fix this... esp with some help. And just see what works and what doesn't. You perhaps have to be a bit of a masochist, though. There's a lot of failure involved in assembly programming, esp when it gets overcomplicated or it's someone else's mess.

*You might also try adding some bitmasks before those addwf PCL instructions. Those are a bit of a problematic thing. We added one to ... feature1, I think it was? You might try doing something that with all of the addwf PCL lookup table subroutines. This is a good idea in general when using that instruction. 
« Last Edit: October 01, 2018, 01:11:27 am by KL27x »
 

Offline ElectrofinnTopic starter

  • Regular Contributor
  • *
  • Posts: 83
  • Country: gb
Re: Assembly code Help! PIC16F57
« Reply #60 on: October 01, 2018, 02:13:37 am »
Excellent, will try your code and do the things you suggested as well. Don't know if you have any idea about the hold problem? no worries if not, you have already done a truck load and I thank you so, so much for all the time and effort you've put in. You have been awesome thank you. Got to go sleep now, got to get up early and get my son to school but will test later today.
« Last Edit: October 01, 2018, 02:20:49 am by Electrofinn »
 

Offline KL27x

  • Super Contributor
  • ***
  • Posts: 4108
  • Country: us
Re: Assembly code Help! PIC16F57
« Reply #61 on: October 01, 2018, 03:13:45 am »
^ I have a few major obstacles, Finn.

I have no clue how indirect addressing works on the baseline PICs, and the datasheet doesn't help.  I used midrange FSR/INDF incorrectly for like 2 years before finally figuring that out. I have very little understanding of how to use software debugging/simulation. And I don't have the device. Not even a bare PIC 16F57, and frankly, I don't really want to learn any more about these obsolete devices. :)

So in many ways, you could debug this better than I, IF you had just a few basic skills and learned just a little bit of assembly programming.

Quote
Don't know if you have any idea about the hold problem?
So... I have super little understanding of how this code actually works, partly because of this INDF/FSR indirect addressing mystery (to me). I have no schematic or hardware. So whatever actual physical manifestation occurs in your device, I have no idea how that relates to the code. Something as simple as a bit of test code to blink a LED and just stopping/looping is super helpful. By moving this test code around and seeing where it breaks/stops the code, one might get an idea of where this "hold problem" actually relates to the code. In the code, the headers and hints left by the creator may be very abstract and far removed from what you think it to be. There are simply no good words to describe half the issues that assembly coders solve, and you might as well have names of race horses in there.

Curiously missing from the programming header information is a pinout or pin designation. There must be some inputs and outputs, and none of that info seems to be included in this asm file. If you have the schematic/device, you would have some more options for testing. Especially if there are any free pins for hooking up to LEDs or a scope or whatnot. 
 

Offline ElectrofinnTopic starter

  • Regular Contributor
  • *
  • Posts: 83
  • Country: gb
Re: Assembly code Help! PIC16F57
« Reply #62 on: October 01, 2018, 08:42:26 am »
Yeah no problem I understand, the assembly language all seems very nonintuitive to me and find the comments in creators code quite vague or don't properly explain what it's doing, at least to me anyway. One thing that baffled me is why he called the table for the servo actuations "odds"  :-// why not call it "servo"... A little odd! Lol. With the problem you solved with the light sequence, I was really surprised and had no idea that what you did was required to get that to work, I felt that there was no chance I would have been able to come up with that, thought It was going to be a simple case of changing a value or range somewhere. Lol though I don't know why I was surprised because when I tried following along with a tutorial to flash a simple led, It seemed like a rediculous number of steps to get that to work, it felt like repeatedly smashing my head against a brick wall would of felt better! Lol

I'm not even sure the flow chart included in the magazine article would be much help to me as that could be based on the finished code. In the flow chart it seems to be asking itself, when in idle mode, is there is any credits? and if yes, is the hold feature active. What this is personally telling me is that the hold feature is suppose to be driven by a random generator, and the literature in the article does say something like this but it seems to be pointing straight to the hold feature when you put that first credit in, yet if during the game you run out of credits and decide to put a credit in, it doesn't always give you a hold but sometimes it does, that's when it seems like it's working correctly... Strange, and I don't quite know how I am going to solve this issue.



« Last Edit: October 01, 2018, 04:30:42 pm by Electrofinn »
 

Offline ElectrofinnTopic starter

  • Regular Contributor
  • *
  • Posts: 83
  • Country: gb
Re: Assembly code Help! PIC16F57
« Reply #63 on: October 01, 2018, 06:23:59 pm »
Wow, KL27x you have been busy, your changes to the main program loop looks awesome and so neat and tidy, it's thing of beauty. still early in my testing but everything appears to be working ok, will update you though. Sometimes I wish it was as easy as that thing in the matrix movie where they upload to their brains what they need to know or learn In a few moments. need the assembly language program uploaded to mine lol


again thank you for everything you have done.  :-+   
« Last Edit: October 01, 2018, 07:33:47 pm by Electrofinn »
 

Offline KL27x

  • Super Contributor
  • ***
  • Posts: 4108
  • Country: us
Re: Assembly code Help! PIC16F57
« Reply #64 on: October 01, 2018, 07:35:06 pm »
Quote
Wow you have been busy, your changes to the main program loop looks awesome and so neat and tidy, it's thing of beauty
This was mostly changing the tabbing to make it more readable. I've spent countless hours doing this to my own code. It's something that feels productive while you are trying to figure out what you should be thinking about. I think there's a word for this in the movie prop industry, but I forget what it is.  It's also useful to leave these marks so you know where you've been and what you haven't really looked at before.

Quote
the comments in creators code quite vague or don't properly explain what it's doing
Probably 60-75% of my own code comments are useless to even myself, 1 week removed from the project. Some, not all, will have a meaning if/when I dig back into it. So I totally forgive the authors for that.

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

So, I did not intend to think about this code today. I was not thinking about it last night. But here it is. I just woke up and was thinking about how I was going to start my day. And a connection just popped into my head out of nowhere. 

this observation of yours
Quote
**update** ok just had instance where a win did part of the "pattern" table, am switching back to new_byte equ 0E for now. although if it were someone else other than me playing the machine you probably wouldn't of noticed it to be honest.   
   

Table and odds are the other addwf pc lookup tables I referred to earlier.

Next, notice how there are only 7 outcomes in "odds". This is an odd choice for an assembly programmer when adding one more would make life easier. Also, notice how the last two values are the same, 0x08. This is also curious. You see the same redundancy in "pattern," where the last two values (as he originally wrote it) were redundant. But at least in pattern, his redundant retlw finished a nibble. In "odds" this redundant value still leaves the table one line shy of "filling the 3rd bit".

Also notice how odds is physically located in front of "pattern".
Notice if w reg were loaded with b'0000111" when "odds" were called, it would jump to pattern. And it would add another 7 to the PC. And it would :
    retlw   0b6

So when you said
Quote
ok just had instance where a win did part of the "pattern" table,

Do you suppose this "part of the pattern table" has any relationship to 0xb6 by any chance?  Was it exactly this "frame?" I'm assuming "display" subroutine turns that into something up there on your display... a 3x 7 segment deal, is it?

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
odds   
   addwf   pc,f
   retlw   28   ;0
   retlw   14   ;1
   retlw   10   ;2
   retlw   0C   ;3
   retlw   00   ;4
   retlw   08   ;5
   retlw   08     ;6


pattern
   addwf   pc,f
   retlw   07f   ;0
   retlw   0bf
   retlw   0df 
   retlw   06f   ;3
   retlw   0b7
   retlw   0db
   retlw   06d
    retlw   0b6   ;7
   retlw   0db
    retlw   0ed
   retlw   0f6
   retlw   0fb   ;11
   retlw   0fd
   retlw   0fe
   retlw   0ff
   retlw   0ff   ;15

   retlw   0ff
   retlw   0ff
   retlw   0ff
   retlw   0ff   ;
   retlw   0ff
   retlw   0ff
   retlw   0ff
   retlw   0ff   ;
   retlw   0ff
   retlw   0ff
   retlw   0ff
   retlw   0ff   ;
   retlw   0ff
   retlw   0ff
   retlw   0ff
   retlw   0ff   ;


pattern2   addwf   pc,f
   retlw   00
   retlw   81
   retlw   0C3
   retlw   0E7
   retlw   0FF
   retlw   0E7
   retlw   0C3
   retlw   81
   retlw   00
   retlw   81
   retlw   0C3
   retlw   0E7
   retlw   0FF
   retlw   0E7
   retlw   0C3
   retlw   81

   
 

Offline ElectrofinnTopic starter

  • Regular Contributor
  • *
  • Posts: 83
  • Country: gb
Re: Assembly code Help! PIC16F57
« Reply #65 on: October 01, 2018, 09:10:06 pm »
Ok just to start, and is probably not relevant to what your asking but I'll get there, below is the values I am now using for "pattern" which is the same pattern as the PIC16C57 I can't access.

pattern   addwf   pc,f
       retlw   80
   retlw   0C0
   retlw   0E0
   retlw   0F0
   retlw   0F8
   retlw   0FC
   retlw   0FE
   retlw   0FF
   retlw   7F
   retlw   0BF
   retlw   0DF 
   retlw   6F
   retlw   0B7
   retlw   0DB
   retlw   6D
   retlw   0B6
   retlw   0DB
   retlw   0ED
   retlw   0F6
   retlw   0FB
   retlw   0FD
   retlw   0FE
   retlw   0FF
   retlw   0FF
   retlw   7F
   retlw   3F
   retlw   1F
   retlw   0F
   retlw   07
   retlw   03
   retlw   01
   retlw   00


I just added a load of 0FF values just for testing at the time because I hadn't yet figured out what the pattern was until recently when you fixed the code for me and was able to run my 32 values. what these values relate to is the 8 yellow leds that are above my segment displays. have attached a picture of the board I am using to test this, this is the old board as it already has the led's soldered in. each value when converted to binary actually corresponds to which leds are lit. so OFF in binary is (11111111) and so all leds are lit or 80 is (10000000) so farthest left led is lit and the rest off ect.


when these values run one by one from the top of the list to the bottom, they create a chasing like led pattern. the first 8 values turn the leds on one by one and stay on as they go, the next 16 values does what I call a twinkle pattern and the last 8 is pretty much the reverse of the first 8, they turn off one by one and stay off as they go. the whole thing loops around and looks very pretty and seamless. it does this only when there are no credits and it keeps doing this until you put a credit in, when a credit is inserted the pattern stops and the leds now become a way of knowing how many credits you have, they light up one by one and stay on as each credit is inserted. obviously there are only 8 leds but even if you put more than 8 credits in, the machine still registers them and the leds only start going off one by one when the credits drop below 8.


now the segment displays I believe are actually controlled from the lookup table called "table" the first value is 40 which translates to a bar on the display, I know this because I changed this once and made two segment light up instead of one bar. as for the repetition In the "odds" table that always confused me. especially since the lowest value is 08 and in decimal is 8 which is 8 servo actuations... but that's four coins (20p)… this confused me because this is not the lowest prize amount, 10p is the lowest which should be 4 servo actuations. but there is no 04 in that list, so I think that a 10p win is read from somewhere else in the code.


please look at this below and go to 6:44 in the vid, you will see briefly the leds doing their thing before he puts a credit in and you'll see the rest of what happens.

https://www.youtube.com/watch?v=GCGmK0gCCUI
   


                 
   
« Last Edit: October 01, 2018, 09:30:07 pm by Electrofinn »
 

Offline ElectrofinnTopic starter

  • Regular Contributor
  • *
  • Posts: 83
  • Country: gb
Re: Assembly code Help! PIC16F57
« Reply #66 on: October 01, 2018, 09:13:11 pm »
here's prize break down
 

Offline KL27x

  • Super Contributor
  • ***
  • Posts: 4108
  • Country: us
Re: Assembly code Help! PIC16F57
« Reply #67 on: October 01, 2018, 09:29:31 pm »
Quote
ok just had instance where a win did part of the "pattern" table,
So when you say this, you "won" and "part of the pattern table" happened, do you mean the 8 LEDs lit up in a piece of the "pattern" table?
And was it the 8th value in pattern, the way you had changed it?
in your revised code that would be 0xFF or all LEDs lit.

FYI, in case this state machine is indeed accurate, it can help you figure out the code.
The main loop calls all the subroutines in sequence, never-ending.
The key to what "state" the program is in is "mode_byte". Depending on what is contained in modebyte, different parts of the Loop become active/inactive.

If you wanted to figure out how the program relates to the state machine flow diagram and to the machine, itself, some basic steps would be
1. figure out which bits of modebyte are actually used. This may be done with by throwing the "mode_byte not previously defined" error code.
     I have already formatted the main loop to tab out the mode_byte checks into their own column. It looks like there may be only 3 or so bits actually used.
2. list all the subroutines which are active in each valid value of mode_byte
3. figure out how that relates to the state machine diagram and/or how the machine is acting.
4. you would also be curious about every place mode_byte is manipulated.

Also, if you were serious about fixing this or improving it, probably a good place to start is drawing up a schematic and putting a pin configuration into the code header, just for reference. That said, I'm not saying I'm going to help you fix it, if you did this. But it is an important step.

One of the things you may learn to do is to use the outputs already on there to debug. Take the 8 LED bar. You could write up a test loop to output the contents of W or mode_byte or w/e other register you are interested in to this 8 LED bar, and now you see the content wherevever you are inserting that to intentionally break the code. Most people might do that in software, but like I said, I'm low tech.
« Last Edit: October 01, 2018, 10:05:18 pm by KL27x »
 

Offline ElectrofinnTopic starter

  • Regular Contributor
  • *
  • Posts: 83
  • Country: gb
Re: Assembly code Help! PIC16F57
« Reply #68 on: October 01, 2018, 10:01:17 pm »
yes it ran part of the revised twinkle pattern which would begin on the 9th but it could have started from the 8th but would not of noticed as it would have been too brief. btw I noticed in the list you posted you are calling the first value of 07f ;0, your counting from 0 where as I am counting from 1, to me that's value number 1 lol just saying because we maybe getting our wires crossed.

everytime you have given me code i went straight in and put my custom pattern in to make sure that worked first.


is that what you wanted to know? or am i not understanding you?
 

Offline ElectrofinnTopic starter

  • Regular Contributor
  • *
  • Posts: 83
  • Country: gb
Re: Assembly code Help! PIC16F57
« Reply #69 on: October 01, 2018, 10:15:17 pm »
What I will do is save this topic thread and try my hardest to learn and work through your advice. I hope you don't feel your wasting your time with your superb write up's because if anything else it is extremely interesting and other people will certainly benefit from it, even if I end up failing to wrap my head around it.
 

Offline KL27x

  • Super Contributor
  • ***
  • Posts: 4108
  • Country: us
Re: Assembly code Help! PIC16F57
« Reply #70 on: October 01, 2018, 10:55:30 pm »
Good idea. I suggest you continually add any notes to the code whenever you make any connection, even if you don't change any actual code.

For instance, you could note

pattern
;the contents of W are output to 8 LED bar (where, physically? RC0-7? which port/pins?) by subroutine XYZ

Have fun but not too much. This kind of problem takes small bites to get anywhere. And it may end up producing only a case of indigestion.


 
 

Offline ElectrofinnTopic starter

  • Regular Contributor
  • *
  • Posts: 83
  • Country: gb
Re: Assembly code Help! PIC16F57
« Reply #71 on: October 01, 2018, 11:12:22 pm »
At least I can see with this the physical side of things, just connecting the dots with the code. for the eagle eyed out there, yes the capacitors are the wrong way around on the lower left of the diagram, part 2 of the article warns about the error.
« Last Edit: October 01, 2018, 11:18:28 pm by Electrofinn »
 

Offline ElectrofinnTopic starter

  • Regular Contributor
  • *
  • Posts: 83
  • Country: gb
Re: Assembly code Help! PIC16F57
« Reply #72 on: October 02, 2018, 12:10:31 am »
oh wait I just re-read your comment about the redundancy of the two OFF values in the pattern table, didn't click at the time. originally there were only 16 values but I found that if I put anything less than 16 it would start running itself into the pattern2 table to make up the 16, the pattern I first put in was done in 15 so I added the extra 0FF to make it 16 so it would loop just the 16 in the "pattern" table.


the odds one is curious and I think I get what your saying now. Is it possible that it jumps to  retlw   0b6 and runs from there? because if your asking did it look like it just run this one value, then no, but it did look like it ran  retlw   0b6 and 7 more values after it.

**update ** your lastest code edit just gave me an instance where on a win it beeped once and maybe ran one value of a table before paying out, maybe that retlw 0b6. Would I just add more redundant values to the odds table to stop it jumping? no wait that's not right argh! I'm confused, so sorry. I need to think about this, but I defo think that's why I am seeing this issue on a win. I think you were on to something. f**k it I'm going to try adding another 08 value on odds table lol     
« Last Edit: October 02, 2018, 01:58:12 am by Electrofinn »
 

Offline KL27x

  • Super Contributor
  • ***
  • Posts: 4108
  • Country: us
Re: Assembly code Help! PIC16F57
« Reply #73 on: October 02, 2018, 01:13:39 am »
No, that's exactly right. At least it's exactly what I was thinking, too.

What it looks like is that last redundant value in the odds table is either coincidentally the only redundant value and which happens to be done in two consecutive lines. OR it is an attempt by the coder to prevent the pointer from going beyond the bounds of what W can be. In this case it would be odd coincidence.

So you are exactly right. By copying that last value and adding it in there to make a total of 8 lines to follow addwf pc in odds, it could potentially "fix it," if this is occurring. Even if it is occurring, it doesn't mean it is causing the problem you saw. In fact, after you described further, it doesn't sound like it. These lists are not performed in sequence, only one of these retlw's is the return point. So if this bad jump happend, "odds" would simply act like the 8th line below the addwf PC instruction happened to be the same line as the 8th line after same instruction in "pattern." It would not cause the "pattern" to "play" on the LEDs. It woudl just cause "odds" to have a perhaps unintended addition to its range, and w/e value was in that 8th spot might or might not cause any problem, but it wouldn't cause "part of the pattern" to light up on the LEDs (unless odds is played out to the LEDS, too, in which case it would only play that 1 frame of pattern, unless there is some other problem). Identifying what port the LEDs are connected to would help in finding the subroutine that actually takes these lookup tables and turns them into the flashing LEDs. The physical part of the problem is something you are still avoiding. :)

This type of error, an occasional glitch is usually caused by
1. Bad jump, like what we are talking about just now. This manipulating PC is one of the big things. But in assembly, all kinds of logical errors by the coder can cause this, from mistakes in using BTFSS/C and otherwise.
2. Shared memory with bad handling.
3. Paging/banking mishandling.

So, to find the glitch, these are the type of things I would be looking for, primarily.
For 2, the memory problem, it is unfortunate that you have only one free register left in bank0. And also, the code uses INDF/FSR. So to figure out what is actually free in the other banks, you would first have to figure out how INDF/FSR works on this PIC and what values are in the range used by the program. Because the code does some calculations to manipulate FSR. Also, even if you do figure out free memory on other banks, using it will require bank bit or banksel, which will be cumbersome. Memory bank handling is essentially analagous to the paging using status bits 5,6 and/or pagesel/lcall to change the page in the hidden/high part of the PC (program counter/pointer), except to the analogous memory pointer.

If there were more free registers on bank 0, the approach I would use is to identify where memory/registers are shared, and see if they can't be separated. For instance, take counter_hi. It's doing something perhaps totally unrelated in auto1/2/3 (but I'm not sure). You could designate a new register as ... counter_higher (lol). And you could change counter_hi to counter_higher in say, just auto1/2/3. It might mess up the program in other ways, of course. *

Now the other issue you had with the machine always starting on a win, this might be an easy fix.
If it's starting the same every time, it must be because of the initialization of memory.
locate init2, and check those registers that are being cleared out. If you're lucky, simply putting ";" in front of the one of the usual suspects will cause the machine to start up randomly (at least pseudorandomly;   undefined memory is sorta random on start, but not truly; for this reason, I think it would be better to just make it NOT payout on the first time).

*In fact, another thing comes to mind. Where that bcf counter_hi,4 instruction was (I forget the title;header, but it was error/instance #11 of counter_hi, IIRC ). Because of the way that this register is used in auto1/2/3, and because of what it does in feature/pattern, this instruction should really be replaced by a bit mask.** If somewhere else, say in autoX, counter reaches 64 or higher, when it gets used to this spot that incf counter_hi and then clears bit 4... well, when pattern is called, that will cause a bad jump.

**
;;;;;;;;;;;;;;;;;;;;;;;;;;
;bcf counter_hi,4
;
movlw b'00001111'
andwf counter_hi,f
;;;;;;;;;;;;;;;;;;;;;;;;;

Sorry if this is getting redundant. This is what I was talking about with adding some bit masks, as relating to making sure these addwf PC commands are staying in their intended playgrounds. So just keep in mind the reasons for this stuff... it's ultimately cuz you are interested in finding/fixing bad jumps and bad memory sharing. But it sounds like you're making some connections.
« Last Edit: October 02, 2018, 02:03:26 am by KL27x »
 

Offline ElectrofinnTopic starter

  • Regular Contributor
  • *
  • Posts: 83
  • Country: gb
Re: Assembly code Help! PIC16F57
« Reply #74 on: October 02, 2018, 02:16:09 am »
Yes lots of it was just bouncing off my head but when I read back your post and together with my experience with messing about with the tables and also a tutorial I was watching the other day about lookup tables and the program counter, which at the time didn't go in, I just had an epiphany.

It's coming I think, be it at a rediculously slow snails pace. Lol
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf