1

I was reproducing the Girino (the Instructable by Caffeinomane) bundled with the Girinoscope (the Java GUI by Chatanga). The results worked well and I went on to see if the oscilloscope can go up to higher kS/s.

In short, originally only upto prescaler 8 works. I removed PWM pin and it works upto 4 but prescaler 2 strangely behaves. Here are the details:

I did a preliminary test on prescaler 32 (~38.5kHz). Settings as follows and the same in other tests.

  • The signal (the same hereafter) is generated by a 555 timer astable multivibrator running at 4.5V (3 AA batteries).
  • The circuitry was simply omitted. I just tied 3.3V of Arduino NANO / ATmega328 to digital pin 6 as the trigger level.
  • There is no +2.5V offset done by the original Girino. (The scale should be 0~5V and the signal is 0~4V) Prescaler 32 works

So then I wanted to try if it can speed up more. The code optimization quoted by Chatanga allowed prescaler 8 and 16 (76.9kHz and 151.8 kHz).

In order to push it the poor Arduino to the limits, I disabled PWM pin in the original Girino which sets the trigger level with duty cycles (PWM from pin ~3 being fed into pin 6). It's because I simply used a fixed 3.3V trigger level.

Prescaler 4 is unlocked. Prescaler 4 works with code optimization and disabled PWM

Ambitious I go on to test prescaler 2. The GUI did not provide this option so I simply set it in the Arduino code. Prescaler 2 strangely behaves (all full scale deflection)

I thought it did not work. I noticed if the prescaler is exceeding the Arduino's capability, TXRX simply does not blink. But this time the TXRX is just blinking! To verify this, I shifted the wait duration. Prescaler 2 strangely behaves (all full scale deflection)

In previous screenshots, the leftmost green line is dashed (probably because it's below fullscale deflection). But in the last two, be it offset or not, the line is solid.

The debug output is like this: (8bits 0~255 given by ADC)

  • many 0 then suddenly 255 thereafter. (matches the GUI output)

I suspect it's due to slow TXRX? How to solve this? Or anything I overlooked?

Hope that this overdetailed question does not sicken you.

0

From the ATmega328P datasheet, section 29.8, "ADC Characteristics":

Clock Frequency — Min.: 50kHz, Max: 1000kHz

With a 16MHz system clock this means that a /16 prescaler is the most the ADC is considered reliable under for a reasonable 10 bit result (for a full 10 bit result the maximum frequency is 200kHz, which corresponds to a prescaler of /80).

As the frequency increases the sample-and-hold circuitry of the ADC gets less time to do the "sample" part before conversion begins. As such any correctness goes out the window, certainly at the lower bits. The fact that you got any sort of result that you did at /4 is luck.

TL;DR: The ADC is too slow.

  • Thanks for your quick answer! The original code sets a 8bit ADC. Does that explain why I can get a /4 result? Aside from this, how low should the resolution be if I badly need a, say, /2 prescaler? – Blue Penelope Jan 1 '15 at 6:22
  • At /2 you should not expect the ADC to work at all. What you need is a faster ADC. – Ignacio Vazquez-Abrams Jan 1 '15 at 6:24
  • So I shall buy a faster ADC IC. – Blue Penelope Jan 2 '15 at 4:56
  • Consider that you also need to get the results into the MCU fast enough as well though. – Ignacio Vazquez-Abrams Jan 2 '15 at 4:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.