mega169 32KHz clock will not start reliably

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

I have a mega169 project that uses th4e async clock for real time. It spends most of the time in sleep mode, and just wakes up every second to update the clock. This has been working flawlessly for me. However - the client wanted an added function that required a minor change to the system startup process. I added the code, and to my surprise, the 32KHz clock will not start after a power-on reset OR if I start the emulator (AVR Dragon) using the "Start debugging and break" option. I can see that TCNT2 never increments. But, if I halt the execution of the emulator, then click run, everything works just fine.

If the board is running standalone, powering up does not result in proper operation (and yes, I DO have brownout reset enabled). However, if I press the hardware reset button, then the system works as expected. The Timer 2 code and the sleep mode code is the same for both setups. It seems that, for some reason, the 32KHz clock does not want to start from certain reset conditions with this additional code (which, BTW, isn't even called until the counter starts!), and I'm clueless as to why.

If I figure out what's going on, I'll post back here, but in the meantime, I'm open to suggestions.

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

So if you put the old firmware in the unit, then it works? Gee, changes to startup, and now it doesn't start? Start with the old and make one change at a time. Or back out one change at a time.

Just for fun, delay 100 Ms as the first thing in main. Does it work then?

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: 1

davetelling wrote:
I have a mega169 project

Which version exactly ?

 

The newer chips need a 6pF low capacitance crystal, other ones used standard 12pF.

 

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

theusch wrote:
So if you put the old firmware in the unit, then it works? Gee, changes to startup, and now it doesn't start? Start with the old and make one change at a time. Or back out one change at a time. Just for fun, delay 100 Ms as the first thing in main. Does it work then?

I have done both of those, and the only thing that seems to work is commenting out the sleep command. Time does not seem to be the issue - I can wait for several seconds and find that the Timer2 counter is not counting, and all config bits are correct. As mentioned earlier, if I manually press my reset button (just grounds the reset line momentarily) when running standalone, OR if using the AVR Dragon emulator, if I just click pause, then run, everything works. It's not a clock hardware problem, since it runs perfectly fine otherwise. It seems that the sleep command has some effect with this new startup that it did not have with the old one. I will keep looking.

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

N.Winterbottom wrote:

davetelling wrote:
I have a mega169 project

Which version exactly ?

 

The newer chips need a 6pF low capacitance crystal, other ones used standard 12pF.

 

Since the clock has been running fine under other firmware, I'm pretty certain that crystal capacitance is not the issue. Something is happening elsewhere in the internal timer hardware.

 

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

davetelling wrote:
I have done both of those

Both of what?  When you put in the old firmware, does it work?  If so, then it would have to do with the new firmware, right, and not any circuit changes? I guess we need one question at a time. 

 

Did you try the startup delay, since you seem to have a power-on-time issue?

 

When you "changed the startup", (boy, this is hard trying to see in the dark) did you creat a path such that you could reach your "sleep" command before you turned on interrupts and/or enabled the wakeup source(s)?

 

You do realize the I (maybe we) will keep poking until you show the differences between versions, in a small complete test program.  Thus, indirectly, you will need to cut down to a simple complete test program.  How many changes were there?  Have you taken them out, and/or inserted them one at a time?

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.