Page 1 of 1

ATmega328p with internal RC oscillator?

Posted: Sun Dec 10, 2017 4:40 pm
by AHorneffer
Hi

I'm working on using micronucleus with the ATmega328p. It works fine with an external 16MHz crystal, but when I try using the internal RC oscillator, then the host doesn't recognize the USB device. In the syslog (on Ubuntu Linux 16.04) I get:
Dec 10 15:33:09 cypresse kernel: [17708.254022] usb 1-7: new low-speed USB device number 87 using xhci_hcd
Dec 10 15:33:09 cypresse kernel: [17708.462266] usb 1-7: device descriptor read/64, error -71
Dec 10 15:33:10 cypresse kernel: [17708.749926] usb 1-7: device descriptor read/64, error -71
Dec 10 15:33:10 cypresse kernel: [17709.037867] usb 1-7: new low-speed USB device number 88 using xhci_hcd
Dec 10 15:33:10 cypresse kernel: [17709.245908] usb 1-7: device descriptor read/64, error -71
Dec 10 15:33:11 cypresse kernel: [17709.534086] usb 1-7: device descriptor read/64, error -71
Dec 10 15:33:11 cypresse kernel: [17709.825904] usb 1-7: new low-speed USB device number 89 using xhci_hcd
Dec 10 15:33:11 cypresse kernel: [17709.853330] usb 1-7: Device not responding to setup address.
Dec 10 15:33:11 cypresse kernel: [17710.086536] usb 1-7: Device not responding to setup address.
Dec 10 15:33:11 cypresse kernel: [17710.293854] usb 1-7: device not accepting address 89, error -71
Dec 10 15:33:11 cypresse kernel: [17710.474133] usb 1-7: new low-speed USB device number 90 using xhci_hcd
Dec 10 15:33:11 cypresse kernel: [17710.502095] usb 1-7: Device not responding to setup address.
Dec 10 15:33:12 cypresse kernel: [17710.737315] usb 1-7: Device not responding to setup address.
Dec 10 15:33:12 cypresse kernel: [17710.942111] usb 1-7: device not accepting address 90, error -71
Dec 10 15:33:12 cypresse kernel: [17710.942149] usb usb1-port7: unable to enumerate USB device


Has anyone used V-USB on the ATmega328p with the internal RC oscillator? What configuration did you use?

P.S. Feel free to join our discussion on the micronucleus pages: https://github.com/micronucleus/micronucleus/issues/107

Re: ATmega328p with internal RC oscillator?

Posted: Mon Dec 11, 2017 7:43 pm
by ulao
The 328's internal clock is not very accurate. v-usb requires a solid clock. You may get it to work by adjust the internal RC oscillator but this is going to take a lot of critical timing.. More on that here. viewtopic.php?t=8819

or go int free

https://cpldcpu.wordpress.com/2014/03/0 ... ree-v-usb/

Re: ATmega328p with internal RC oscillator?

Posted: Wed Dec 13, 2017 11:30 am
by AHorneffer
I understand that V-USB requires a precise clock. But for micronucleus it doesn't have to be stable for long times, only a minute or so, then all the transfer is done.

I understood it that the 12.8 MHz mode was made to work with the internal RC oscillator of some of the chips. So I'm wondering if it should also work on the ATmega328p, or if its internal oscillator doesn't cut it.

Re: ATmega328p with internal RC oscillator?

Posted: Thu Dec 14, 2017 11:10 am
by horo
Hi,

Did you also try the 16.5 MHz version? If I look at the F vs. OSCCAL drawing on p. 607 of the datasheet* with split OSCCAL and you use the default starting value of 128 you're in the upper half that starts with 6..6.5 MHz (-> clock frequency 12..13 MHz) and grows. Better use the lower half, starting value e.g. 64..80. for 12.8 MHz clock frequency.

Ciao, Martin

* http://www.atmel.com/Images/Atmel-42735 ... asheet.pdf

Re: ATmega328p with internal RC oscillator?

Posted: Thu Dec 21, 2017 1:36 pm
by AHorneffer
Did you also try the 16.5 MHz version? If I look at the F vs. OSCCAL drawing on p. 607 of the datasheet* with split OSCCAL and you use the default starting value of 128 you're in the upper half that starts with 6..6.5 MHz (-> clock frequency 12..13 MHz) and grows.


[I guess you mean figure 33-39 of the datasheet. At least that's what I'm referring to.]
Where do you get that doubling of the frequency? The internal RC oscillator of the ATmegas is specified for 8 MHz. The with the OSCCAL register one can push it to around 13 MHz, but that's about it.

In general: micronucleus has some code that tries to calibrate the OSCCAL on the frame time of the USB bus. I can see it speeding up the MCU when it is connected to the USB, so it does something. But it doesn't seem to be good enough.

P.S. I didn't find any mention of using V-USB on the ATmega328p with the internal oscillator, so I guess that just doesn't work.

Re: ATmega328p with internal RC oscillator?

Posted: Fri Dec 29, 2017 9:20 pm
by lgberro
Hi AHorneffer!

I am trying to make atmega328pb run with internal oscillator at 12.8MHz. We could share our achievements.

Re: ATmega328p with internal RC oscillator?

Posted: Thu Jan 11, 2018 5:15 pm
by horo
AHorneffer wrote:Where do you get that doubling of the frequency? The internal RC oscillator of the ATmegas is specified for 8 MHz. The with the OSCCAL register one can push it to around 13 MHz, but that's about it.

In general: micronucleus has some code that tries to calibrate the OSCCAL on the frame time of the USB bus. I can see it speeding up the MCU when it is connected to the USB, so it does something. But it doesn't seem to be good enough.

P.S. I didn't find any mention of using V-USB on the ATmega328p with the internal oscillator, so I guess that just doesn't work.


Sorry, the frequency doubling is a feature of ATtiny25/45/85 (-> Fig. 6-2 of the data sheet) that is not available on ATmega :(
ATtiny is able to select a path from the 8 MHz RC oscillator through an 8x PLL with a following 1/4 freq divider to get 16 MHz system clock. So the 16.5 MHz approach is only usable on an ATtiny.

Ciao, Martin

Re: ATmega328p with internal RC oscillator?

Posted: Thu Dec 06, 2018 1:39 pm
by AHorneffer
Hi

lgberro wrote:I am trying to make atmega328pb run with internal oscillator at 12.8MHz. We could share our achievements.


A bit late, but just FYI: I gave up trying to use VUSB on the ATmega328p with the internal oscillator.
I use it with 12MHz or 16MHz crystals.

Re: ATmega328p with internal RC oscillator?

Posted: Fri Jan 25, 2019 3:57 am
by lgberro
AHorneffer wrote:Hi

lgberro wrote:I am trying to make atmega328pb run with internal oscillator at 12.8MHz. We could share our achievements.


A bit late, but just FYI: I gave up trying to use VUSB on the ATmega328p with the internal oscillator.
I use it with 12MHz or 16MHz crystals.

and I did make it work with internal oscillator at 12.8 MHz... :mrgreen:

Re: ATmega328p with internal RC oscillator?

Posted: Mon Feb 04, 2019 8:04 pm
by AudyIltis
Hi...I used it before on an ATmega8 with heavy serial port needs... No problems whatsoever. This was almost ten years ago too, not sure if the internal oscillator in AVRs has changed much lately.You can now use the oscillator pins as a RTC and save the external chip.
I'm testing it out on an old ATmega16, and maybe create a library if it works out ok.