Running V-USB on an ATmega8 without using a crystal
Posted: 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!
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!