Generate a 3.58MHz clock at atmega16u2

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

Hi, I'm new at Atmega microcontollers and I'm not a pro in the game so I need your help :)

 

I have an Arduino Uno Rev3 to do my project and I will work with the Atmega16u2.

Since the Arduino board apply a 16MHz external crystal oscilator to Atmega16u2, generate a clock signal with 4Mhz don't seem to be a problem.

Generate a 4MHz clock signal with CTC mode should be something like that:

 

    TCNT0=0;                        // initialize the counter to 0    
    OCR0A=4;                        // Compare to 4 cycles  (16MHz/4MHz = 4MHz toggle)
    TCCR0A = 0x42;                    // Toggle OC0A on Compare Match, CTC Mode
    TCCR0B = 0x01;                    // No Prescaler

 

I not tested this code yet because it's not I want to do. I want to generate a specific 3.58Mhz clock signal on the OC0A pin.
How can I do that? What value OCR0A should be to the OC0A pin toggle at 3.58MHz?

 

Thank you in an advance for your help!

This topic has a solution.

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

It can only give you an integer division - 16/3.58 is not an integer division. Simple solution - either use a crystal that is a multiple of 3.58 or just use another crystal.

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

either use a crystal that is a multiple of 3.58 or just use another crystal.

Only thing about that is that this is a 16U2. Presumably it's chosen for the "U"? That means the *only* options are 8MHz or 16MHz.

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

Hmm. Pretty tall order for a 16MHz chip. That's a cycle every 4.46 instructions. Perhaps you could find a 14.32MHz crystal?

274,207,281-1 The largest known Mersenne Prime

Measure twice, cry, go back to the hardware store

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

"Colorburst" or similar video app?

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

Which AVRs have a PLL and can do hi freq pwm?

Imagecraft compiler user

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

The Atmega16u2 is one of these.

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

Which AVRs have a PLL and can do hi freq pwm?

 The Atmega16u2 is one of these.

Hmmm--that opens a few more possibilities, eh?

 

If using 18 cycles at 64MHz I think that is about 1% off.  Maybe close enough?

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

I see no evidence in the datasheet that that AVR model can do high-speed PWM.

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

Sorry, maybe I'm confused with Fast PWM mode.

Like I said I'm new to the Atmega microcontrolers. Please don't punish me :S

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

It can only give you an integer division - 16/3.58 is not an integer division. Simple solution - either use a crystal that is a multiple of 3.58 or just use another crystal.

Only thing about that is that this is a 16U2. Presumably it's chosen for the "U"? That means the *only* options are 8MHz or 16MHz.

Hmm. Pretty tall order for a 16MHz chip. That's a cycle every 4.46 instructions. Perhaps you could find a 14.32MHz crystal?

 

The reason that I'm working on an Arduino board and atmega16u2 is the USB interface. Soon in my project I must implement that.
I didn't an exaustive search on that, but as I know to work on USB interface I must active the PPL mode on Atmega16u2 to generate a high frequency clock for USB interface (48MHz) wich is multiplied from an external clock input.
Since I will need an oscilator wich value is multiple of 48MHz, do I must find a crystal oscilator that works on a multiple value of 3.58MHZ and 48MHz? :S

Maybe it's time to look for another solution.

 

Thank you again

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

Maybe it's time to look for another solution.

I haven't seen a description of the problem that is in search of a solution.  Is there a need for 3.58MHz in the app?  How so?

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

Like I said above...

I need to build an app to generate a clock signal with a specific frequency of 3.58MHz on OC0A pin in Atmega16u2.
My problem is generate this clock through 16MHz oscilator on the Arduino board.

 

The 3.58MHz signal clock will be used to activate and communicate with another microcontroller and the data will be transmited later through an USB port. 

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

The 3.58MHz signal clock will be used to activate and communicate with another microcontroller ...

So, what is the need for this particular frequency?  What type of "communication" is this?

 

As I mentioned, that frequency is "colorburst", right?  Some kind of video app?  What do you mean by "activate"?

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

What did you mean with "colorburst"?

I need a 3.58MHz frequency to activate a CLK line on a smart card.

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

What did you mean with "colorburst"?

I need a 3.58MHz frequency to activate a CLK line on a smart card.

The ISO standard aligns with the use of two widely used external clock frequencies, 3.579545 MHz and 4.9152 MHz. The former frequency is the more widely used (being based on the NTSC colour sub carrier frequency) and results in a clock divider of 372 in order to produce a 9600 bit per second (not exact but within tolerance) serial communication speed. The latter frequency has a simple divisor of 512 in order to achieve a 9600 bit per second communication speed. The standard defines the situation after reset whilst allowing the frequency to be selectively changed by means of protocol type selection. 

My quick reading suggests that the absolute frequency has some tolerance--as long as you are able to decipher the resulting UART stream being returned.  

 

This blog indicates a wide acceptable range?

http://www.gregmefford.com/blog/...

Generating a Smart Card Clock

The first requirement of interfacing the microcontroller to a Smart Card is to provide the card with a stable clock between 1 MHz and 5 MHz. Even though the data IO interface of the ACOS5 Smart Card is asynchronous, the card requires a continuous clock on the CLK pin in order to operate. This was accomplished rather simply using the ATtiny2313’s hardware PWM function.

Colin O'Flyn just said "you need a fast clock"--no value(s) given:

http://www.colinoflynn.com/tiki-...

 

Alberto Ricci Bitti appeared to use a "simple" 4MHz value:

http://www.riccibitti.com/NUT_ch...

 

 

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

Is it just cost that says the AVR itself has to generate this 3.58MHz? The simple solution would seem to be to simply get a canned oscillator. Searching 3.57..3.68 on digikey the first items you hit that can be ordered 1-off (not 1000+ !) appear to be a bit over $1.

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

This blog indicates a wide acceptable range?

http://www.gregmefford.com/blog/2010/06/05/avr-meet-smart-card/

Generating a Smart Card Clock

The first requirement of interfacing the microcontroller to a Smart Card is to provide the card with a stable clock between 1 MHz and 5 MHz. Even though the data IO interface of the ACOS5 Smart Card is asynchronous, the card requires a continuous clock on the CLK pin in order to operate. This was accomplished rather simply using the ATtiny2313’s hardware PWM function.

Colin O'Flyn just said "you need a fast clock"--no value(s) given:

http://www.colinoflynn.com/tiki-view_blog_post.php?postId=26

 

Alberto Ricci Bitti appeared to use a "simple" 4MHz value:

http://www.riccibitti.com/NUT_chips/card/card.htm

 

 

Hum... I didn't saw this articles. My support was this one:

 

The clock signal is used drive the logic of the IC and is also used as the reference for the serial
communications link. There are two commonly used clock speeds 3.57 MHZ and 4.92 MHZ. The
lower speed is most commonly used to date in Europe but this may change in the future. 

One may be tempted to ask why these strange frequencies were chosen, why not just a straight 5 MHZ. The
reason lies in the availability of cheap crystals to form the clock oscillator circuits

 Font: http://www.smartcard.co.uk/tutor...   , (3ºpage on 2ºparagraph)

 

But looking to the links that you gave me, maybe I understood this wrong.
I've been understood that I need a specific 3.57MHz frequency, but may 4MHz it work just fine. The reason they chosen 3.57MHz was the availability of the oscillators on that range. 

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

Can you tell us more about your overall project?

 

It is not uncommon to have more than 1 chip in a project.

Perhaps the M16U2 runs the USB interface to the PC, and runs the majority of the rest of the project, and you have a second chip which generates the 3.58 MHz signal?

 

What is the signal being used for?

 

Lots of options for the second chip, including dedicated oscillators, nand gates, or another uC with an external crystal of 3.58 MHz, or a multiple of it.

 

JC

 

Edit:  Darn.  I hate it when I don't see that a Thread continues onto Page 2...

Last Edited: Wed. Oct 1, 2014 - 05:20 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Lol thats ok!
However, I want to build a smart card reader to read and write to a smart card (citizen card).
I'm not very interested in to add an extras microchips to not increase the overall cost of the project.

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

Nowadays,   crystals of any frequency are cheap.    So there is no point in looking for 'surplus' 3.58MHz crystals when you can buy a new 4MHz or 8MHz crystal.    Or even a new 3.58MHz crystal if you really want to use this frequency.

 

You might even choose to run the MCU @ 20MHz and generate 5MHz from a Timer in CTC mode.

Or choose an AVR with a PLL.   And generate a suitable frequency by dividing the PLL.

 

David.

Last Edited: Wed. Oct 1, 2014 - 07:28 PM