[ASM] How mirror unknown count?

Go To Last Post
11 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I get an unknown count value in a register between 6 and 2, how can I mirror this count?
For example.

cnt=6 |cnt=5
-------------
543210|43210| ccw
012345|01234| cw

I think max count minus current count? But how to keep on track? Result of ccw and cw must be both directions counting down from max to 0.

RES

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

indeed.

I have to say that I can't understand what you are after at all - want to try explaining what you are after in a slightly different way?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What you describe does not match the picture.

Normally, you "count" by incrementing some variable. Each time the counting event occurs, the counter value is increased by one. These do no appear in discrete locations and it is not like your picture (unless you "count" by shifting a bit through a register).

So, some additional explanation would help. How are you counting?

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yet another one of RES' famous riddles :)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

OK, a closer relook at the OP suggests that this may involve a rotary encoder since it refers to "CW" and "CCW".

However, that still does not explain what the code is now doing or how RES wants it to be done. More explanation, please!

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

Yet another one of RES' famous riddles

Yes, be warned people that RES is a known troll who poses this kind of question seemingly not for any practical purpose but simply to trigger the headless chickens. Be warned - you may be wasting your time.

Cliff - moderator.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Don't feed the trolls. 8)
Here's the ASM code I am working on.

	cp	chrWmax, chrWval
	brne	exitCW
	ldi	YH, high(SRAM+80)		;Y -> character buffer
	ldi	YL, low(SRAM+80)
	dec	chrCount			;to previous character
	rcall	bldChar				;build character in buffer
	dec	chrWmax
fixCcnt:adiw	YL, 1
	dec	chrWmax
	brne	fixCcnt
	ret
exitCW:	sbiw	YL, 1
	inc	chrWval
	ret

Expl: In one register I get a count value of 6, 5, 4, 3 or 2.
Every ccw click of the rotary encoder the count goes from max value to 0, and every cw click the count must go to that max value (6, 5, 4, 3 or 2), so the count reverses. This happens for example (changing direction suddenly.):

54345
dec dec dec inc inc
ccw ccw ccw cw cw

Via dec/inc, but it must also drag Y with it. But when reloading a new (proportionated) character the max count is again in the chrWval register and Y at 0, but must be at that max value (which is only known in chrWval)
Is there not another way to accomplish this? I can use shifting a bit, but then I bump into the same problem, don't know which bit the count will end.
(chrWval = character width value)

RES

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Don't you love dodgy asm code! I still have no clue as to what the intention is, nor can I infer it from the code. Why the hell would you have encoder counts in registers except for intermediate calcs - especially when it is a slow device and would you bother to name the registers? It all seems too 'tight' to me.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Are you looking for size or speed ?
Perhaps remove the loop and add chrWmax to Y
to Kartman:
The code is something like this (not tested)
Y and X is pointers to unsigned char


if (chrWmax==chrWval){
  Y=X;
  chrCount--;
  bldChar();
  chrWmax--;
  while(chrWmax--)
    Y++;
}
else
  chrWval++;
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Maybe you can explain the goal of your coding.
I understand absolutely nothing.

Peter

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think he is describing a state machine where you are given an initial max value. This value determines the endpoint of an array. By examining your array index and the previous array index you determine your current state.
The mirroring thing is just a way of saying you are moving to the left or right in the array.