ATmega328p with internal RC oscillator?

General discussions about V-USB, our firmware-only implementation of a low speed USB device on Atmel's AVR microcontrollers
AHorneffer
Posts: 4
Joined: Sun Dec 10, 2017 4:23 pm

ATmega328p with internal RC oscillator?

Postby AHorneffer » Sun Dec 10, 2017 4:40 pm

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

ulao
Rank 4
Rank 4
Posts: 477
Joined: Mon Aug 25, 2008 8:45 pm

Re: ATmega328p with internal RC oscillator?

Postby ulao » Mon Dec 11, 2017 7:43 pm

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/

AHorneffer
Posts: 4
Joined: Sun Dec 10, 2017 4:23 pm

Re: ATmega328p with internal RC oscillator?

Postby AHorneffer » Wed Dec 13, 2017 11:30 am

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.

horo
Rank 2
Rank 2
Posts: 62
Joined: Tue Mar 04, 2008 2:26 pm
Location: Berlin & Lindau, Germany

Re: ATmega328p with internal RC oscillator?

Postby horo » Thu Dec 14, 2017 11:10 am

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

AHorneffer
Posts: 4
Joined: Sun Dec 10, 2017 4:23 pm

Re: ATmega328p with internal RC oscillator?

Postby AHorneffer » Thu Dec 21, 2017 1:36 pm

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.

lgberro
Posts: 1
Joined: Fri Dec 29, 2017 9:17 pm

Re: ATmega328p with internal RC oscillator?

Postby lgberro » Fri Dec 29, 2017 9:20 pm

Hi AHorneffer!

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

horo
Rank 2
Rank 2
Posts: 62
Joined: Tue Mar 04, 2008 2:26 pm
Location: Berlin & Lindau, Germany

Re: ATmega328p with internal RC oscillator?

Postby horo » Thu Jan 11, 2018 5:15 pm

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


Return to “V-USB”

Who is online

Users browsing this forum: No registered users and 1 guest