ATTiny461 Timer0 in free-running counter mode.

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

Hi!

I have a small problem here... I am building a flash source in BASCOM. Most of it works fine, except for the Timer0. For some reason (I am guessing the chip definition file was botched) I cannot configure the Timer0 in 16-bits free-running counter using BASCOM statements...

Here is what my code looks like:

   Config Pina.4 = Input
   Config Timer0 = Counter , Edge = Rising                  

....

   Tcnt0h = 0 : Tcnt0l = 0                                  
   Do         ' Wait until 400 cycles have passed
   Loop Until Tcnt0l => &H90 And Tcnt0h = &H01

Now although this should work fine, it does not, as I said probably the chip def file that's broken.

Could anyone point me in the right direction about initializing Timer0 in free-running 16-bits Timer mode in assembly?

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

I'm not a user of that chip, but isn't Timer0 an 8-/16-bit timer? I'd think you'd need to configure it differently for the alternate width.

When you say "free running", do you mean that you want the timer running "by itself", or clocked with an input pin as your code implies?

Lee

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

Well I will have an input clock connected to ICP0, I just need it to keep counting from the moment I initialize it, no interrupt on overflow.. As far as setting it in 16-bits mode, from the datasheet page 74, setting ICEN0 and TCW0 will set it in 16-bits input capture, but I'm guessing there is more to it that this to start the timer itself.. Also does the fact that I am initializing pina.4 (ICP0) as an input inhibit the input capture function?

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

Maybe I should have added the error a little more precisely... If I try to compile the above code in BASCOM, it yields an error on the "config Timer0" line, saying TCCR0 is not defined (on Tiny461 it's TCCR0A and TCCR0B). What I am missing is the appropritate config for the TCCR register I am guessing?

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

Quote:

Well I will have an input clock connected to ICP0, I just need it to keep counting from the moment I initialize it, no interrupt on overflow.. As far as setting it in 16-bits mode, from the datasheet page 74, setting ICEN0 and TCW0 will set it in 16-bits input capture, but I'm guessing there is more to it that this to start the timer itself.. Also does the fact that I am initializing pina.4 (ICP0) as an input inhibit the input capture function?

While that 8/16 timer is a bit of a weird beast, there are a couple of things. You said "free running", you spec'ed "COUNTER, you said "input clock". That ain't "input capture". For external clocking you want to use the T0 pin, not ICP0.

CodeVision's Wizard gives me

// Timer/Counter 0 initialization
// Clock source: T0 pin Rising Edge
// Mode: 16bit top=FFFFh
TCCR0A=0x80;
TCCR0B=0x07;
TCNT0H=0x00;
TCNT0L=0x00;
OCR0A=0x00;
OCR0B=0x00;

which is TCW0 and CS00/1/2.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

Ah crap, yep wrong pin, thanks mister, will not make that mistake again... :)

Thanks for the TCCR settings too...

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

Hi!

I have a small problem in attiny 861a timer 0 overflow interrupt ... Interrupt is generating ,i had make sure through overflow interrupt flag.But if i put any variable count in ISR its not updating..

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

I gather you're using avrgcc. In that case, declare the shared variable volatile.