Single stepping Atmega328 with 555 timer

Hi,

Many of y'all are probably familiar with Ben Eater. I saw his tutorials on the 555 timer chip and thought, would it be possible to use it as a clock for the Atmega328? It would be nice since I can then single-step through my program which would make debugging way easier.

Thanks!

iamericmin:
It would be nice since I can then single-step through my program which would make debugging way easier.

I very much doubt that! :roll_eyes:

Using external clock - either 555 or some other source can be done and you can surely switch to single stepping. I think it can help in some timing sensitive tasks but I am not sure if it will help debugging much.

A 555 might not be fast enough to generate clean logic transitions(*) for a fast CMOS chip, put its output
through a 74HC14 or similar schmitt-trigger device to sharpen it up. Slow transitions on a logic input
can cause multiple clocking. I'd strongly recommend using a CMOS version of the 555, such as the 7555
to reduce power supply noise spikes.

A handy debugging technique for microcontrollers I use is to toggle an output pin in the code in key places,
so that a 'scope can observe timing - assuming you have a 'scope. With single-stepping you can use the
same trick but with LED to observe the pin.

(*) You might not realize that logic inputs generally have a minimum slew-rate specification - slow changes
in voltage can lead to undefined behaviour due to oscillation for instance, and will greatly reduce noise-immunity.

A logic analyzer may be used instead of a scope.

Often it is possible to enable the CKOUT fuse to monitor the timing sensitive sequences. I think it is more convenient than producing external clock.

MarkT:
(*) You might not realize that logic inputs generally have a minimum slew-rate specification - slow changes
in voltage can lead to undefined behaviour due to oscillation for instance, and will greatly reduce noise-immunity.

AVR already have Schmitt trigger on all its inputs. AFAIK minimum slew rate is not specified in the data sheet.

Now I'm curious. Does anyone know how many
CPU clock cycles it takes to complete, say, an
analogRead() command?
Herb

On an ATmega328, the ADC alone requires 25 ADC clock cycles for the first conversion and 13 cycles per subsequent conversion. How many CPU cycles that is depends on the ADC clock divider setting.

Add to that the cycles required to configure it, initiate the conversion and then read it out.

Thank you, jremington. So that would be very many button presses
for the proposed single step process. It doesn't sound practical!

Does the ATmega328 have debug ability? I use PIC's and they can single-step debug through the IDE with the appropriate programmer/debugger device (PICKit).

MK1888:
Does the ATmega328 have debug ability? I use PIC's and they can single-step debug through the IDE with the appropriate programmer/debugger device (PICKit).

Yes, the AVaRICE debugger for example.

aarg:
Yes, the AVaRICE debugger for example.

Great way to go if you want to drop $100. Or you buy the atMega328 xmini board with the build in debugger for < $10.

herbschwarz:
Thank you, jremington. So that would be very many button presses
for the proposed single step process. It doesn't sound practical!

This particular example would probably fail anyway because the ADC has a minimum clock speed. IIRC 50kHz.

herbschwarz:
So that would be very many button presses for the proposed single step process. It doesn't sound practical!

That was my point in #1. :roll_eyes:

aarg:
Yes, the AVaRICE debugger for example.

How does this actually work? :astonished: