Simulate external clock source for timers

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

Hi,

I am doing a project with the AVR-based AT90USB1287 and I need to do some actions based on an external clock. For example I need to change the value of an I/O pin whenever I detect X clock edges.

My solution is to use timer1 (could be timer3 as well) and put the external clock input to pin T1 (PD6). I've set up TCCR1A to 0 and TCCR1B to 7 (external clock source; clock on rising edge).

The problem that I am facing is that I cannot simulate this external clock source in AVR Studio (version 4.18 ).

I've seen that I can modify the PIN values of each port, but even though I try to modify the PIN values of PD6 (T1) on a constant frequency, the counter TCNT1 doesn't increment.

A very simple code used to increment TCNT1 from an external clock might be this:

static uint16_t tmp;

//start timer1 from external source (T1)
TCNT1 = 0;			// initial value
TCCR1A = 0;			// normal operation
TCCR1B = 0x7;

while(1)
{
   if(TCNT1 == 0)
	tmp++;
}

Leaving aside the fact that I am not disabling interrupts while I read TCNT1, the problem is that I cannot simulate the external clock source (i.e. TCNT1 always remains 0).

I didn't find a solution on this forum (or I wasn't able to find the corresponding post) nor on google.

Can anybody help me with this issue please? I would like to be able to simulate the external clock source as it will be a very important part of my project.

Thank you

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

I think you are hoping for more than the simulator delivers. It can't even get the simple stuff right let alone a more esoteric requirement like this one. You'd be far better off running the code in a real AVR with an OCD interface.

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

I apologies for my lack of knowledge, but what is the OCD interface and how do I use it?

Thanks.

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

OCD=On Chip Debug. Most recent AVRs (and some of the older ones) have this in one of two formats: JTAG on multi-pin devices and debugWire on AVRs with fewer pins. To inetrface to the chip in this way you need a device such as the Dragon ($50) or the JTAGICEmkII ($299) or even clones of the original JTAGICE ($30+ - but only for a limited range of JTAG AVRs)

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

Thanks for the reply. I was afraid you were suggesting that. I was hoping to avoid those solutions :)

However a "trick" to my problem is to use the normal prescaler instead of external clock, just for simulation purposes. But it would be nice to have this feature in the simulator as well. Maybe this should be added in the "wishlist" I've seen for AVR studio 5.

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

I've bought the AVR dragon. Much cheaper (30 pounds) than I expected and works great.

For those who are not sure what can it do, I can tell you that it does pretty much everything you need: programming over many interfaces (ISP, JTAG, parallel, etc.), on chip debugging over the JTAG interface, etc.

Now I consider it an essential tool. Forget about the simulation. Pay the 30 pounds for this and you can see exactly what's going on the chip at every clock.

Thanks for the hint clawson.

Omar