Manual stepping of the processor clock

Hello, I would like to manually tick the clock of an arduino uno processor. I thought I could simply replace the quartz with an impulse circuit, but I believe some change are to be made on the bootloader. I don't really know what I am doing, but must be done, do you have any idea about how to change the bootloader ? I did not find someone who did it already (which is weird no ?), I hope it's not too weird of a need. Thank you in advance for your help.

Why????

You probably need to have a switchable clock - between the nominal 16MHz crystal and your static ‘ticker’.

Remember upon reset, the bootloader takes a while to timeout ~1s…, in single tick mode, that means you’ll need to toggle the click button 16 million times just get past the boot loader. Then almost all peripheral activities like Serial won’t work without a lot of coding.

Interrupts won’t work as you expect, as they also depend on the cpu clock to branch & return in the appropriate time.

What you want to do is interesting and familiar to old guys like me (Z80 etc), but you need a good reason to make it useful !
If it’s purely for exploration & experimentation - you may be better off getting one of those naked TTL computer kits, or an IMSAI 8080 emulator to single step your machine code.

@lastchancename "Interrupts won't work as you expect, as they also depend on the cpu clock to branch & return in the appropriate time."

Could you elaborate on that a bit? I don't understand why static clocking would interfere with taking an interrupt and returning to normal program flow as usual.

Slowly. Any relation to time that a program required or expected would be out the window of course, but the chip's basic responses should be identical?

I wouldn't be surprised to miss, say, a pulse interrupt that a normally clocked chip would see, but that's just one of many many things that would be quite different. Only the same way I would expect to miss, say, a regular input not being held high for enough cycles to run through code that reads it.

TIA

a7

The interrupts will work much as expected, but remember, the hardware takes a finite number of clock cycles to respond, so I wouldn’t be surprised to see you click away a decent number of ticks before you see your ISR being entered ! Same for the return....

As per the 328P data sheet... Entering an interrupt and the corresponding return both take a minimum of four clock cycles / plus of course the surrounding code to implement the handler.

@lcn Right, thanks.

I think your observation "you'll need to toggle the click button 16 million times just get past the boot loader" says it all, LOL.

a7

For the ATmega controllers:

AFAIK runs the bootloader on the 8MHz RC clock.

The prescaler can be changed to slow down the external clock at any time.

What about a hardware circuit which provides both a 16MHz clock and a manual single step? Clock source can be controlled by DUT and a user-controlled toggle. Circuit gives regular clock until end of setup then sets an output which switches the hardware over to the manual clock.

By the same token the clock could be switched back to 16MHz under program control to zip through selected sections of code.

What about an Arduino emulator? That also can show controller internals...

Thank you all for your help, I will try to clarify, I want to listen (with an antenna) to the processor to get the exact em emission due to the change of state of the processor. But the arduino must boot correctly, to load the exact program I want (otherwise I will have unrepeatable malfunctions) I want to make sure the processor can : 1) run the program as it should but in slow mo ( 2) hold the state he is in) -> I guess trials will tell, but if someone is knowledgeable about processor 's establishment and hold time please explain me :)

See #6. EM effects depend on speed, where steep slopes also are fast at any repetition rate. You'll need a more sophisticated laboratory for hacking execution flow from EM.

PerryBebbington: Why????

Very good question. I don't think it has been explained yet. :astonished:

DrDiettrich: See #6. EM effects depend on speed, where steep slopes also are fast at any repetition rate. You'll need a more sophisticated laboratory for hacking execution flow from EM.

I don't think so, the establishing currents will be as fast, whatever the clock timing I want step by step to precisely detect witch current is witch and to stop the strong noise clock make. What i don't know is how the processor will accept being manually clocked ( he could change state after too long, crashing everything and ruining the purpose) That is my question, how long can the processor be kept interrupted before being unstable ? And does his electric supply rely on the clock to regulate tension ?(ex : a pid alimentation tune with the clock, whithout clock the voltage will no longer be regulated)

OK, so there are a few things wrong with that.

The processor is CMOS. When halted, it should draw zero current, apart from that being supplied to or sunk from I/O pins, so measuring current is nonsense.

Similarly, with no clock operating, it does not care how long it stays in that state.

Voltage regulation is the precinct of the voltage regulator; it has nothing to do with the processor.

After reading the Atmel data sheet, I suspect your stopper will be the watchdog timer that is started when power is initially applied to the processor. If the power is not correct withing just a few ticks of the watchdor, nothing will continue. Paul

Hi, If you do manage to get single step clock, do you have a logic analyzer to find out what data or address lines cause the greater EMC as they transition. Not all lines will transition with each clock step and so you will need to identify the changing lines.

Layout of the wiring/pcb also has a lot to do with EMC.

I am not trying to discourage you, but have you got all the variables covered in your experiment?

Tom... :)

Note the warning in the ATmega328p datasheet: "When applying an external clock, it is required to avoid sudden changes in the applied clock frequency to ensure stable operation of the MCU. A variation in frequency of more than 2% from one clock cycle to the next can lead to unpredictable behavior. If changes of more than 2% is required, ensure that the MCU is kept in Reset during the changes. "

If you want your ATmega328p to run very slowly you can use a 32.768 kHz crystal oscillator and then set the system clock prescaler to 256 to get the clock speed down to 128 Hz. If you disable interrupts and pulse a pin to trigger a digital storage oscilloscope you should be able to watch the current draw of each instruction in the code under test.

Controller current can be measured only directly at the controller pin, after all capacitors. Even then a byte addition will yield different current depending on the number of toggling bits.