Assembler Question
Tapperman
Posts: 319
I'm using Mr. Schwabs PWM object http://obex.parallax.com/objects/467/ and I'm trying add the following logic to the assembler section (Main_PWM_Loop):
If P8 = 1 let the assembly modify Pins 13 thru 15 normally.
But, if P8=0 then set Pins 13 thru 15 to Zero.
I need to integrate it into the same cog. But, I'm not sure how I can accomplish said task?
... Tim
If P8 = 1 let the assembly modify Pins 13 thru 15 normally.
But, if P8=0 then set Pins 13 thru 15 to Zero.
I need to integrate it into the same cog. But, I'm not sure how I can accomplish said task?
... Tim
Comments
Yes ... Very, Very, Very close to the target!!!
Thankyou so much!
In keeping with one of the earlier post's regarding 'solutions' ... when I get the answer, I'll post the solution.
... Tim
Now I just need to figure out what the timing constant changes too?
Would it be 8204?
... Tim
As for the period, the main loop - when running uninterrupted consumes exactly 41 hub windows (16*32+4*32+4+12 = (40+1)*16, 656*12.5 = 8200). So you could either raise it to 8400 (since you're adding 1 hub window, 16*12.5) or move the or temp, Ch + 08 to the front (swap with Ch + 00, i.e. mov temp, Ch + 08 wz) and grab the flag state without timing penalty (8200).
Also, I was unaware the the Zero flag would be set in that test d,s for all case's the Propeller manual PDF says:
Thanks for the clarification and the calculation:
... Tim
Thanks for all your help, here is where that code went:
pin 8 drives my FIELD switch and pins 13, 14 and 15 are the 3 phase signal used to drive motor with.
Because of the way the IGBT's get power, I have to turn the bottom switch on now and then to charge the 1000 uF cap that powers the top IGBT boards (6 in all, 3 top and 3 bottom).
Due to construction an output on pin 13-15 of 0, turns on the bottom switch ... and outputing a '1' turns the top switch on. changing the dira to input on any of these pins, prevents either switch from operating!
... Tim
OK, next stupid question ... Is there an easy way to calculate modulo in assembly?
... Tim
It depends on the divisor. 2^N is a simple AND. Some other constant values can be calculated by a sequence of shifts, adds and subtracts. Other otherwise it's a modified divide routine.
Well, maybe that's the wrong approach ... maybe the question should be:
Is there a way to read the motor encoder and create a pattern like this:
... Tim
OK ... so
57 mod 9
could be done by:
... Tim
You mean out of this entire forum ... none of you have a modulus routine in assembly? (shaking the tree, as it were)
... Tim
I was able to replace a modulus routine in assembler by putting my bit pattern repeated in a long and then using ROL for 1 direction and ROR for the reverse direction. My pattern was a 4 bit pattern and I did a ROL,#4 then transfered the new pattern to a temp variable and then anded %1111 with it to get the necessary pattern. SHL,BasePin then moves it to the correct output..
Jim
Thankyou for the feed back .... do you have a example piece of code lying about I might be able to look at?
... Tim
I didn't catch that! Thank you!
I got the motor to run today using a spin version of my Idea ... but it does not go very fast.
And, this is what I think is close to same?
Maybe there is a better way to preform 'case' in assembly? Any Ideas?
... Tim
Thank you very much for your reply!
First, I understand what you mean by binary tree to divide your outputs. And I'm not sure why I didn't see that before? I guess I can't see the forest for the tree's.
Second, I do not understand what you mean by dereference SV_Index? After all, this is my first attempt at putting together a assembly driver! Could you explain for me please!
... Tim
There are a few different ways to handle what you want to do. Easiest is probably something like:
1st thanks for all the help!
But, I'm now having an issue with PASD ... I am able to single step through the example that came with it, but not my own code? I've double checked that I have kernel copied correctly (and no, no char's are at column 0) ... and after reading through some of the old post's that got deleted, discovered that you can not have a CON section following your code ... I'm ok there too, nothing follows my DAT section.
I've included a copy of code here. Any ideas?
1st, your correct that @SV_Asm is passed to cognew. But, that only happens if I press the 'PLAY' button on my remote (see Install_Motor method)! In the debug version ... @entry is passed. However, I think you pointed me in the right direction ... my assembly start routine passes the @command spin var as a second variable in the cognew command, but in the debug cognew, that doesn't happen!
Is that a problem? Because the first 'step' in PASD is mov temp, par and nothing has been passed! And, that is the instruction that 'crashes' the PASD session!
2nd, what do you mean by "ord'd incorrectly"?
3rd, why don't I want to use jmp set_vector?
... Tim
PS - still learning!
Well, you start the DAT block with org 0 which is followed by the debug kernel. Those 12 longs push your program back so you can't run it as if it were located at 0 (which is what your cognew would do). In English, all the address references are wrong.
The current form is an indirect jump. It takes the content of set_vector (mov outa, SV_Index) and uses the lower 9 bits as a jump target. The source field contains the address of SV_index which is $07B (with debug kernel). If you want to jump to the set_vector label use the direct form (jmp #set_vector).
I can't believe I missed that!!!!!! After all the reading & studying ... but after that change, the driver started working! My first assembly driver (well, it's actually 90% owed to you and this forum!) and the motor turns correctly!
Thank you so much for your input!!! Still one more challenge to over come, but that's down hill from where I am now! Need to come up with a method to detect the best acceleration for any given offset value? With the remote, I can change the offset by pressing '7' or '9' on the remote (by 16) and also by pressing the 'up' or 'down' arrow keys (by one).
Since the motor driver can be installed at any shaft position (detected by E4P object), the offset that best moves the motor in your desired direction must be found!
... Tim