I/O-ing Frequencies on ATMega8

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View
So I recently acquired some ATMega8's for a project. My biggest need
right now is for somebody to point me in the direction of some guides
and code for specific programming on the ATMega8. Most specifically I
am using these to output a frequency (Highs and lows and 5 and 0 Volts)
using a circuit to process the signal and send it back to the
microcontroller where the incoming frequency will be sent out again.
The main purpose is to deteriorate the frequency's integrity/accuracy
as much as possible through doing this process multiple times. It
sounds strange, I know, but if you have any links or references to some
pre-written codes or explanations on how to do this, I'd be very

Thanks a bunch,


Re: I/O-ing Frequencies on ATMega8

Quoted text here. Click to load it

I doubt very much that there's pre-written code.

You set bits and then you read bits. You could use one of the timers to
wiggle an OC bit or use a PWM or just loop and do and SBI/CBI. Read with
an IN and write with an OUT, or perhaps use an interrupt pin. Are you
going into/out of of a single AVR or a chain of multiple?

What are you trying to do?

Rich Webb   Norfolk, VA

Re: I/O-ing Frequencies on ATMega8

Quoted text here. Click to load it

Depending on the ferquencies involved, you might want to look at the imput
capture and PWM

Re: I/O-ing Frequencies on ATMega8
Quoted text here. Click to load it

I don't have a clear understanding of what you are trying to do.  Are
you toggling an output line to generate a square wave, driving a D/A,
programming a frequency synthesizer. or something else?

What kind of processing are you doing externally?  Are you then
attempting to measure the frequency with same processor?  If so, why
would it be different?  How are you capturing the modified signal?
How long are you maintaining your output frequency?

Quoted text here. Click to load it

Why would you expect the signal's frequency to change?


Re: I/O-ing Frequencies on ATMega8
Ok, so I now realize that I need to be a bit more specific.

So let me clarify the purpose. Basically what I am trying to do is have
the ATMega8 output a square wave from two pins at a frequency (the
frequency does not matter as I'll explain in a minute). One pin needs
to output a low and one pin a high (Low being 0 Volts, High being 5
Volts) so that I have at each time a single pin giving a high and a
low. Both signals are sent to an IC that will process the signal (the
way it processes it does not matter) and send a signal back to the
microcontroller hopefully at the same frequency (thats what I am
testing). I will then need this signal coming from the IC to be used as
input to the microcontroller via one pin and output yet again via
another pin to another IC. This will happen for 3-4 ICs, and I will
analyze the frequency at certain points at calculate signal loss as a
percentage (assuming there is signal loss, since that is the point of
doing this test) compared to the number of ICs. If perhaps I run out of
room on my single 28 pin ATMega8, then I will have to move to another
ATMega, but I am hoping to keep it on one ATMega.

So basically here is what has to happen on the Microcontroller:
I generate an identical original signal from two different pins on the
I then have to receive a signal and output the received signal from a
different pin.

Hopefully that clarifies the purpose/procedure.

Rich Webb:
Quoted text here. Click to load it

I was afraid of that since my google searches turned up very little. I
need to go back and look more closely at the AVRFreaks website and
forums and see If I can turn up something. However now that I've
explained it a little better perhaps somebody can point me towards some
pre-written code that has bits and pieces of what I am trying to do. I
really need some good sources to some Assembly or C code that contain
things like input output and generating with PWM or internal clocks.

And just so nobody worries- I have the IC/analog portion of my circuit
already planned out so I don't think I need much help there. Its just
in the coding of the uC that I need a little push in the right



Re: I/O-ing Frequencies on ATMega8
Quoted text here. Click to load it

So, it woulds like you will be testing for frequency deviations or
'jitter' created by the ICs under test.  If this is correct, and you
want to measure this linearly, then you can't use one microcontroller
and loop the signal in and out several times, because the outputs will
all be synchronised with the uC clock.

  You also mention signal loss. If you are interested in amplitude, note
that the uC will always output 0 and 5V, no matter what level it gets on
the input.  Maybe you mean modulated signal distortion?

  So far it's not sounding to me like the AT megas are what you need to
do this project.  Try using a simple function generator and a spectrum

Re: I/O-ing Frequencies on ATMega8
Quoted text here. Click to load it

Yes, thats pretty much what I would like to do. Luckily I have extra
uCs so this should not be a problem. The frequency deviation is really
what I was trying to convey in the above post. This is for a
demonstration for people who won't necessarily know what a 'frequency
deviation' would be (uCs are will be like magic boxes to some people
reviewing this) so I have been using 'signal integrity' as a blanket
term for it, though I recognize that it is not the same thing.

So now it occurs to me that what I really need to do is use one uC to
generate the signal and send it to the IC, which sends it to another uC
whose internal clock will be determined by the incoming signal and then
output the signal, which outputs to another IC, and repeat over and

My other issue is budget in that I can't do this project too
excessively, though I will recycle the components. So any expensive
equipment is out the window at this point.

Also, I am trying to recreate 'real world' conditions with this
project, so using things that are not necessarily used in consumer
electronic products would make this project moot.

Thanks, and if you still have some resources on ways to do this, I'd be
much appreciative.

Re: I/O-ing Frequencies on ATMega8
So that I make sure, I should use PWM for this task correct?

Re: I/O-ing Frequencies on ATMega8
Unless I'm missing something about what you're trying to do, I really don't
see the point of using the microcontroller as a repeater.  It will introduce
lots of error which will mask the effects you are trying to measure.  Just
stick with a simple digital or analog buffer.  I suppose you could use a
microcontroller to generate the initial signal but that is still overkill.


Quoted text here. Click to load it

Re: I/O-ing Frequencies on ATMega8
Quoted text here. Click to load it

the pwm would be the easiest way to generate a fixed or oscillating
frequency square wave from the uC.  


  If you want to show people what frequency deviation is, here's an
idea.  I don't know what chip you are using to skew the clock (the chip
under test), but if it can handle clock I/O frequencies of around 3 MHz,
you could use an audio coax s/pdif signal as the clock source and run
that through your chip(s) and run the resulting signal back to a s/pdif
to analog converter (like in most modern stereo amps).  Then you could
HEAR the frequcncy deviations in noise.

the a->d

Re: I/O-ing Frequencies on ATMega8
Well the actual purpose of the experiment was to try and force the IC
to degrade the signal, but use the uC to degrade it even more. I am
sure, in fact know there are better ways to do it, like the way you
described, but I have to be able to do this most importantly
quantitatively and at the time I submitted my proposal I decided to go
with uCs and ICs because that is what I knew I could at least get
something with even if it wasn't exactly what I was looking for.

When Henry Hallam above says that it will introduce more error, that is
what I am trying to do. Introduce as much error to the system as

Thanks for all the help, and if you have some more ideas it would be
nice to hear some, but from here on out I think I need to be focusing
on the uC programming.


Re: I/O-ing Frequencies on ATMega8
["Followup-To:" header set to alt.electronics.]

Quoted text here. Click to load it

it'll give you nice stable square wave without your code needing to
explicitly switch the pin on and off for each transition.

It may be possible to set up a second pwm for the inverted signal, or it may
be easier to just use an inverter.


Re: I/O-ing Frequencies on ATMega8
["Followup-To:" header set to alt.electronics.]
Quoted text here. Click to load it

there's a bunch of stuff on the ATMEL website, all AVR series processors
use the same assembler language, they just have different resoources, and
some have extra op-codes.

but from your description it sounds like an bunch of D-type flip-flops clocked
from different clocks could give you the time-domain distortion you appear to


Site Timeline