Running V-USB on an ATmega8 without using a crystal

General discussions about V-USB, our firmware-only implementation of a low speed USB device on Atmel's AVR microcontrollers
Post Reply
n-regen
Posts: 5
Joined: Tue Aug 10, 2010 9:51 pm

Running V-USB on an ATmega8 without using a crystal

Post by n-regen » Fri Aug 13, 2010 3:26 pm

Although it was written in here quite often that one cannot run V-USB on an ATmega without using a crystal, i have tried to overclock an ATmega8 to 12.8MHz and use it as an HID.
I tried different OSCCAL-values and found out that 0xEF (239) results in a clock frequency of 12.700MHz at 5V, while 0xF0 (240) will result in a clock frequency of 12.917MHz - and both of these values are sufficiently close to 12.8MHz to use the V-USB-firmware.
So, if you don't want to use a crystal, but do want to use V-USB, you can set the OSCCAL-register to about 0xEF/0xF0 at the very beginning of your µC-program (best set before anything else is done). You might need to alter the value a little, because every ATmega is different (that's why OSCCAL was invented in the first place: to correct differences in the internal oscillator caused during production). To find a suitable value, you will propably have to use trial and error by either setting OSCCAL to an arbitrary value near 0xEF, flashing the controller and looking if it works or by controlling the frequency on an oscilloscope (e.g. you can set up a 16-bit PWM and multiply the PWM-frequency displayed on your oscilloskope with 65536 to get the actual clock frequency).
As usual: Be warned that the clock frequency differs greatly with temperature and even more with supply voltage (you will propably be unable to reach a clock frequency of 12.8MHz when running the ATmega on less than 5V).
I am not responsible for any damage or unreliability caused by this advice!
Last edited by n-regen on Sun Aug 15, 2010 3:01 am, edited 2 times in total.

frank26080115
Rank 2
Rank 2
Posts: 43
Joined: Fri Jun 19, 2009 4:43 pm

Re: Running V-USB on an ATmega8 without using a crystal

Post by frank26080115 » Sun Aug 15, 2010 1:42 am

excellent, although calibration might get a little annoying when you try making multiple devices, thanks for the information.

the way you write numbers was a little confusing at first, then i remembered some countries use commas for decimals, where are you from?

n-regen
Posts: 5
Joined: Tue Aug 10, 2010 9:51 pm

Re: Running V-USB on an ATmega8 without using a crystal

Post by n-regen » Sun Aug 15, 2010 3:00 am

It might be possible to implement an automatic calibration like the one used on ATtinys (e.g. in the EasyLogger example), but as I'm currently planning to build only one or two ATmega-based USB "projects", manual calibration seemed sufficient and I did no further research about how to compute the OSCCAL-value automatically.
I have replaced the commas in my first post to avoid confusing people. I'm from Germany, where we use commas to separate the number from the decimals, while splitting the number into blocks with points or spaces (e.g. 12.345,67 or 12 345,67). However, we sometimes use points for decimals, too, so I'm used to both writing styles (and to the confusion caused by this mix).

Post Reply