extracting TCNT0 in Tiny11

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

I notice when I do a:

in r25,TCNT0

that the counter value never gets into r25. I imagiine the value is 0. Studio 4.11 shows r25 having the TCNT0 info but the next instruction:

cp r18,r25

fails the compare and the Tiny 11 doesn't work in my proto board.

Has anyone encountered this and what's you solution to load TCNT0 into a reg?

Thanks,
Rob

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

Quote:
I imagiine the value is 0.

If the timer is running, this is actually quite unlikely, since you're
just sampling a changing counter.
Quote:
Studio 4.11 shows r25 having the TCNT0 info but the next instruction

The Studio simulator allows you to see what's actually in TCNT0, as well as in r25;
you can then step through the cp/br and see what it does.

If you're still having trouble, post your code; someone will probably have a suggestion.

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

Have you checked the flags in the status register? They should show what is happening. I just added your statements to a Tiny11 program of mine and the flags seemed to be behaving properly.

Leon

Leon Heller G1HSM

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

Yes, I stepped through the code. all the regs. show the proper value. The answer is in the cp statement not working that gives the real indication of r25

rpmTst:
in r25,TCNT0;loads low bit speed value
out TCCR0,clear ;stop Tmr
cp r20,r19 ;r20,r19?
brlo Spd ;r20 = r19-1 or less?
breq RpmTst2 ;r20 = r19?
rjmp RpmNG ;ng r20>r19 (spd slow)
RpmTst2: ;yes equal
cp r18,r25 ;r18,r25?
brge Spd ;r18 > or = r25,yes
RpmNG:
clr r24 ;no clr duration reg
cbi Portb,4 ;relay off
rjmp Start ;no back to spd tst
Spd:
sbrc r24,0 ;spd duration tst

If r20 is greater then r19 it should step down to RpmTst. It does. IF r18 is greater than r25 it should go to RpmNg It jumps to Spd indicating that r25 is less than r18. I tried the code with a 2313 and it works right. I noticed that the 11 shows the in statement only working with ports 'P'
The way to test it is to build a running timer and then checking the cp r18,r25 statement. You can try it with the in statement before or after the stop timer statement with no change. It shows r25 being loaded but I think this is false.

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

Try it with r25 greater then r18 to see the failure.

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

You can eliminate the code after the stop time up to the cp r18,r25 for simplicity.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
   cp   r18,r25 ;r18,r25?
   brge Spd     ;r18 > or = r25,yes
RpmNG: 

Quote:
IF r18 is greater than r25 it should go to RpmNg

No, it should go to Spd if r18 > r25 -- that's how BRGE works.

Incidentally, TCNT0 is pretty much intrinsically unsigned; normally
I'd expect to see a BRSH rather than a BRGE. I suppose it doesn't
matter if you make certain that TCNT0 never counts very high.

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

Thank you. It worked with the BRSH statement but notthe BRGE. So I must have a misunderstanding of signed unsigned.
Perhaps you could give me an example.
Thanks again,
Rob

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

Picking a number more-or-less out of the air: 0xC0 is -64 (signed) and 192 (unsigned) --
same bits, different interpretation.

0x00 is GE (signed) to 0xC0.
0x00 is not SH (unsigned) than 0xC0.

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

Thanks again,
I never really looked at the signed/unsiged in all the time I've been playing with these things. Maybe that's why every once and awhile I have a 'sniggling' little problem.
You've helped.
Rob