MEGA328 running at half speed

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

Hi

Can anyone help:

I have an application using a mega218AU, running at 3.3V, the part uses the internal 8MHz osc, clock div is cleared and the prescaler is not enabled (set  to 0)

the problem is the part seems to be running at 4MHz, I tried as simple loop on a port pin:

check_rx:
        sbi        io_reg,data_pin
        nop
        nop
        cbi        io_reg,data_pin
        rjmp    check_rx

At 8MHz this should give me a square wave with a period of ~0.5uS (at 0.125uS per cycle) but it giving me 1uS, I can't fathom out why it's happening, I never seen this with any other AT parts, having used the mega 64, 90USB, Tiny etc. If I run the simulator and set the frequency to 8MHz the delays are correct. I've tried running the part at 5V, clkout is correct, clock div8 is cleared. If I change the prescaler to 1/8 (1MHz) the square wave period goes up to 8uS, it's almost like the internal cpu osc is being divided by two. OSCCAL is set to A1 (the factory default setting)

I also tried a 100mS interupt, this works correctly with the clock set to 8MHz.

I've also tried a couple more of the prototypes both with the same problem.

I must be missing something obvious, I've never used this particular part before and on a tight shcedule to get the code finished, so if anyone offer any clues, I'd be very appreciative!

cheers

Rob

 

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

robcarter wrote:
At 8MHz this should give me a square wave with a period of ~0.5uS (at 0.125uS per cycle) but it giving me 1uS, I can't fathom out why it's happening,
Why would you say that an 8-cycle loop would take .5us at 8MHz?

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.

Last Edited: Mon. May 8, 2017 - 05:30 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

robcarter wrote:
I never seen this with any other AT parts, having used the mega 64, 90USB, Tiny etc.

The cycle counts for your fragment are the same on all AVR8.  (might be different on brain-dead e.g. Tiny10 family, and Xmega, and some of the new-fangled models)

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

Hi

its not the whole loop, it's the time delay between pin transistions that should be around 0.5uS, so the period is around 1uS

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

theusch wrote:

robcarter wrote:
I never seen this with any other AT parts, having used the mega 64, 90USB, Tiny etc.

The cycle counts for your fragment are the same on all AVR8.  (might be different on brain-dead e.g. Tiny10 family, and Xmega, and some of the new-fangled models)

yes I relaise that, but on this it seems that each cycle is taking twice the time, which is what I can't seem to fathom out, I'll run a tiny84 board up later and compare is on that.

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

robcarter wrote:
so the period is around 1uS
robcarter wrote:
this should give me a square wave with a period of ~0.5uS (at 0.125uS per cycle) but it giving me 1uS

 

See the source of my confusion?

 

If the clock source is indeed correct (how have you checked that?) then about the only thing left is CLKPR.

 

[edit] ...or OSCCAL value of 0

 

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.

Last Edited: Mon. May 8, 2017 - 06:25 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

@robcarter: Please read out the fuses and report here what you get.

 

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

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

theusch wrote:

robcarter wrote:

so the period is around 1uS

 

robcarter wrote:

this should give me a square wave with a period of ~0.5uS (at 0.125uS per cycle) but it giving me 1uS

 

 

See the source of my confusion?

 

If the clock source is indeed correct (how have you checked that?) then about the only thing left is CLKPR.

 

Yes, sorry its been a long frustrating day!, I verified the clock frequency usung the clkout setting in the fuses and scoping PB0, I'm going to run a tiny88 board up with the same code and see if I get the same result. before investigating further

 

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

robcarter wrote:
I verified the clock frequency usung the clkout setting in the fuses and scoping PB0

That is indeed the "right" way to do it.  As CKOUT shows prescaled system clock, that eliminates CLKPR and OSCCAL of 0.

 

So, show a complete test program that demonstrates your symptoms.

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.

Last Edited: Mon. May 8, 2017 - 06:33 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi

I powered down everything, pc, usb, pcb for 1/2 hour, came back the problem seems to have gone away, thank goodness!

I was using the debug wire interface to run the program, so not sure if that could have been causing the issue, I had already powered all the kit down for a short time but the fault kept coming back.

Thanks for your suggestions, sorry about the confused post initially.

Rob

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

I'm not a big debugWire person, but I can see that a debugger in some kind of "auto-step" mode might affect the real program.

 

What was that dude's name?  Heisenberg?  https://en.wikipedia.org/wiki/Un...

 

Simply, measuring will always affect a particle property, so it's impossible to simultaneously measure all particle properties correctly.

That article goes on to say

Historically, the uncertainty principle has been confused[5][6] with a somewhat similar effect in physics, called the observer effect, which notes that measurements of certain systems cannot be made without affecting the systems, that is, without changing something in a system.

...so more properly the "observer effect"? https://en.wikipedia.org/wiki/Ob...(physics)

In physics, the term observer effect refers to changes that the act of observation will make on a phenomenon being observed. This is often the result of instruments that, by necessity, alter the state of what they measure in some manner.

Now, does that apply to AVR8 ICE-type operations?  ;)

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.

Last Edited: Mon. May 8, 2017 - 07:00 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

theusch wrote:
What was that dude's name?  Heisenberg?

Yes. With certainty. (-:

 

Old joke, I know. But keeps fresh even when repeated..

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

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

JohanEkdahl wrote:
Yes. With certainty. (-:

Is there a dead cat involved?  No, that was that other dude...

 

[great to have you back, Johan -- everyone else knows that any acknowledgement of my bad joke attempts will just encourage me]

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.