Wendo
Posts: 142
Joined: Sun Jun 10, 2012 8:27 pm

Question about Atmel chip

Sat Oct 27, 2012 12:40 am

Hi

I've assembled my Gertboard successfully but it shipped without the 3 buffer chips so my ability to test it is pretty limited.

I've uploaded the example blink program to the AVR and connected my logic probe to the pin being used and can confirm it's cycling as expected, however if I disconnect the ribbon cable between the pi and the gertboard the AVR doesn't restart.

This seems to be tied to the jumper leads from the GPIO pins to the SPI programming header for the AVR. If I remove them then disconnect/reconncect the ribbon cable the AVR immediately starts as expected, however while those jumper wires are in place the AVR won't start when powered up

Is this a result of the buffer chips not being installed, that I've done something wrong, or normal operation?

Thanks

User avatar
wallarug
Posts: 460
Joined: Mon May 14, 2012 8:21 am
Location: Sydney, Australia

Re: Question about Atmel chip

Sat Oct 27, 2012 4:25 am

I also have a question about the ATMEGA chip on the board.

Can I use the same sketch that I created for my Arduino Uno and upload it to the Gertboard ATMEGA chip?

I am not using any delay() commands so this should not effect the operation. Also, what are the default timer speeds as well on the ~12MHz @ 3v3 version of the chip?

User avatar
Gert van Loo
Posts: 2485
Joined: Tue Aug 02, 2011 7:27 am
Contact: Website

Re: Question about Atmel chip

Sat Oct 27, 2012 5:57 am

Wendo wrote:Hi

I've assembled my Gertboard successfully but it shipped without the 3 buffer chips so my ability to test it is pretty limited.

I've uploaded the example blink program to the AVR and connected my logic probe to the pin being used and can confirm it's cycling as expected, however if I disconnect the ribbon cable between the pi and the gertboard the AVR doesn't restart.

This seems to be tied to the jumper leads from the GPIO pins to the SPI programming header for the AVR. If I remove them then disconnect/reconncect the ribbon cable the AVR immediately starts as expected, however while those jumper wires are in place the AVR won't start when powered up

Is this a result of the buffer chips not being installed, that I've done something wrong, or normal operation?

Thanks
I do not know the details of the SPI port on the ATmel why it would not work.
But I do know the buffers have nothing to do with your ATmel chip not starting.

User avatar
Gert van Loo
Posts: 2485
Joined: Tue Aug 02, 2011 7:27 am
Contact: Website

Re: Question about Atmel chip

Sat Oct 27, 2012 5:59 am

wallarug wrote:I also have a question about the ATMEGA chip on the board.

Can I use the same sketch that I created for my Arduino Uno and upload it to the Gertboard ATMEGA chip?

I am not using any delay() commands so this should not effect the operation. Also, what are the default timer speeds as well on the ~12MHz @ 3v3 version of the chip?
Yes your image will work. But as you yourself noticed the X-tal is 12 MHz not 16 so all your timer values will be off.
As to the default timer speed:There is no default timer speed. Default the timers are off until your program sets them up.

User avatar
wallarug
Posts: 460
Joined: Mon May 14, 2012 8:21 am
Location: Sydney, Australia

Re: Question about Atmel chip

Sat Oct 27, 2012 6:08 am

Gert van Loo wrote:
wallarug wrote:I also have a question about the ATMEGA chip on the board.

Can I use the same sketch that I created for my Arduino Uno and upload it to the Gertboard ATMEGA chip?

I am not using any delay() commands so this should not effect the operation. Also, what are the default timer speeds as well on the ~12MHz @ 3v3 version of the chip?
Yes your image will work. But as you yourself noticed the X-tal is 12 MHz not 16 so all your timer values will be off.
As to the default timer speed:There is no default timer speed. Default the timers are off until your program sets them up.
On the Arduino Uno, the default timer0 is 62.5 KHz and on timer1 and timer2 it is ~32KHz.

How can I set timer0 and timer1 to ~65 KHz on the Gertboard Chip?

User avatar
alexeames
Forum Moderator
Forum Moderator
Posts: 2869
Joined: Sat Mar 03, 2012 11:57 am
Location: UK
Contact: Website

Re: Question about Atmel chip

Sat Oct 27, 2012 8:10 am

Wendo wrote: This seems to be tied to the jumper leads from the GPIO pins to the SPI programming header for the AVR. If I remove them then disconnect/reconncect the ribbon cable the AVR immediately starts as expected, however while those jumper wires are in place the AVR won't start when powered up
I'm sure Gordon mentions this somewhere on his site as a known issue.
Alex Eames RasPi.TV, RasP.iO

User avatar
wallarug
Posts: 460
Joined: Mon May 14, 2012 8:21 am
Location: Sydney, Australia

Re: Question about Atmel chip

Sat Oct 27, 2012 12:18 pm

Where can very specific information be found for the ATMEGA chip in the Gertboard? This would be helpful to many people.

User avatar
panik
Posts: 369
Joined: Fri Sep 23, 2011 12:29 pm
Location: Netherlands

Re: Question about Atmel chip

Sat Oct 27, 2012 1:03 pm

wallarug wrote:Where can very specific information be found for the ATMEGA chip in the Gertboard? This would be helpful to many people.
On the Atmel webpage for the chip, look for the datasheet on the 'documents' tab (first two links).
http://www.atmel.com/devices/atmega328p ... =documents

User avatar
[email protected]
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: Question about Atmel chip

Sat Oct 27, 2012 1:38 pm

wallarug wrote:Where can very specific information be found for the ATMEGA chip in the Gertboard? This would be helpful to many people.
Start here:

https://projects.drogon.net/raspberry-pi/gertboard/

In essence... The ATmega is running at 12MHz. It's also supplied blank. So the first thing you need to do is to program the device fuses that tell it how its clock generator works and what flash to reserve for a bootloader (none in this case).

To do this, you need to use 4 female-female jumpers from the SPI ports on the Pi/Gertboard to the ISP header on the ATmega, then install the Arduino IDE (apt-get install arduino), then install my newer version of avrdude (actually, it's an older version patched for the Pi), then run the avrsetup program.

Once you've done that, you can use the Arduino IDE as normal, but specify the correct board/chip type - that'll set the correct F_CPU in the Arduino headers and the timers/clock, PWM, etc. will be programmed correctly at program boot time.

-Gordon
--
Gordons projects: https://projects.drogon.net/

User avatar
[email protected]
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: Question about Atmel chip

Sat Oct 27, 2012 1:59 pm

Wendo wrote:Hi

I've assembled my Gertboard successfully but it shipped without the 3 buffer chips so my ability to test it is pretty limited.

I've uploaded the example blink program to the AVR and connected my logic probe to the pin being used and can confirm it's cycling as expected, however if I disconnect the ribbon cable between the pi and the gertboard the AVR doesn't restart.

This seems to be tied to the jumper leads from the GPIO pins to the SPI programming header for the AVR. If I remove them then disconnect/reconncect the ribbon cable the AVR immediately starts as expected, however while those jumper wires are in place the AVR won't start when powered up

Is this a result of the buffer chips not being installed, that I've done something wrong, or normal operation?

Thanks
If you're using my stuff, then try this:

Code: Select all

  gpio unexportall
  for i in 7 8 9 10 11; do gpio -g mode $i in; done
  for i in 7 8 9 10 11; do gpio -g mode $i tri; done
There is an issue with avrdude in that it doesn't un-export the GPIO pins after use, so sometimes they interfere with the operation of the ATmega.

I keep meaning to re-patch it - it's on my to-do list though.

-Gordon
--
Gordons projects: https://projects.drogon.net/

Wendo
Posts: 142
Joined: Sun Jun 10, 2012 8:27 pm

Re: Question about Atmel chip

Sat Oct 27, 2012 8:33 pm

[email protected] wrote:
Wendo wrote:Hi

I've assembled my Gertboard successfully but it shipped without the 3 buffer chips so my ability to test it is pretty limited.

I've uploaded the example blink program to the AVR and connected my logic probe to the pin being used and can confirm it's cycling as expected, however if I disconnect the ribbon cable between the pi and the gertboard the AVR doesn't restart.

This seems to be tied to the jumper leads from the GPIO pins to the SPI programming header for the AVR. If I remove them then disconnect/reconncect the ribbon cable the AVR immediately starts as expected, however while those jumper wires are in place the AVR won't start when powered up

Is this a result of the buffer chips not being installed, that I've done something wrong, or normal operation?

Thanks
If you're using my stuff, then try this:

Code: Select all

  gpio unexportall
  for i in 7 8 9 10 11; do gpio -g mode $i in; done
  for i in 7 8 9 10 11; do gpio -g mode $i tri; done
There is an issue with avrdude in that it doesn't un-export the GPIO pins after use, so sometimes they interfere with the operation of the ATmega.

I keep meaning to re-patch it - it's on my to-do list though.

-Gordon
Fantastic, at least I've managed to put the board together right :)

That was my big concern, but since it's a known issue then I'm in the clear, at least until the buffer chips turn up and I can check the rest of it.

One more question while I'm here, I assume the 6 pin programming header for the ATmel is in the standard pin layout, ie I should be able to use a normal programmer connected to my PC on that header too right?

User avatar
[email protected]
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: Question about Atmel chip

Sat Oct 27, 2012 9:19 pm

Wendo wrote:
One more question while I'm here, I assume the 6 pin programming header for the ATmel is in the standard pin layout, ie I should be able to use a normal programmer connected to my PC on that header too right?
Yes you can - but remember the Pi is a "pc" too - and can run the Arduino IDE with a programmer connected to a USB port, connected to the ATmega on the Gertboard.

That's how I started programming it before working out I could use the Pi's own GPIO pins directly.

I did burn a serial bootloader into it too at one point - modified to run at 12MHz, but it just seemed easier to use the ISP header since you'd have to use it in the first place to burn the bootloader...

-Gordon
--
Gordons projects: https://projects.drogon.net/

User avatar
wallarug
Posts: 460
Joined: Mon May 14, 2012 8:21 am
Location: Sydney, Australia

Re: Question about Atmel chip

Sat Oct 27, 2012 11:58 pm

@[email protected]

I have read through all your content on your website. It has great information about how to set-up the chip but does not have information of default clocks.

@panik

I have read through some of the data sheets there but I cannot seem to find what I am looking for. All I would like is a basic summary that has the timer speeds for the Atmega328p running at [email protected] volts. All the information for Arduino Uno s are summarised nicely on the Arduino Forums and website for the 16Mhz Chip (http://www.arduino.cc/playground/Main/T ... Cheatsheet). I would like the same information for the chip on the Gertboard.

Wendo
Posts: 142
Joined: Sun Jun 10, 2012 8:27 pm

Re: Question about Atmel chip

Sun Oct 28, 2012 1:08 am

[email protected] wrote:
Yes you can - but remember the Pi is a "pc" too - and can run the Arduino IDE with a programmer connected to a USB port, connected to the ATmega on the Gertboard.

That's how I started programming it before working out I could use the Pi's own GPIO pins directly.

I did burn a serial bootloader into it too at one point - modified to run at 12MHz, but it just seemed easier to use the ISP header since you'd have to use it in the first place to burn the bootloader...

-Gordon

Thanks, I figured as much. My reasoning is that the development environment on the PC is much nicer (and faster) so, at least while I'm learning and am in for a lot of compiles I figure the PC might be the better platform

User avatar
panik
Posts: 369
Joined: Fri Sep 23, 2011 12:29 pm
Location: Netherlands

Re: Question about Atmel chip

Sun Oct 28, 2012 2:01 am

wallarug wrote:I have read through some of the data sheets there but I cannot seem to find what I am looking for. All I would like is a basic summary that has the timer speeds for the Atmega328p running at [email protected] volts. All the information for Arduino Uno s are summarised nicely on the Arduino Forums and website for the 16Mhz Chip (http://www.arduino.cc/playground/Main/T ... Cheatsheet). I would like the same information for the chip on the Gertboard.
In the list on the page you link to, the <setting> part is how to set the prescaler to the value of the 'divisor', and is what's in bits CS02, CS01 and CS00, the 3 LSB (least significant) bits of register TCCR0B (in the case of TIMER0). Look for the correct bits to set on page 108-109, table 15-9 of the 'complete' datasheet.

Consider that: Frequency = F_CPU / prescaler / 256 (the time it takes for an 8 bit timer to wrap around.)

Take the first example on the page you link to, TIMER0 has a frequency of:
16000000 / 1 / 256 = 62500 (setting 0x01)
16000000 / 8 / 256 = 7812.5 (setting 0x02)
...
...
So far, those are the same values as on the cheat sheet.

For 12Mhz, those values would be:
12000000 / 1 / 256 = 46875 (setting 0x01)
12000000 / 8 / 256 = 5859.375 (setting 0x02)
...
...

I'm sure you'll be able to calculate the rest of the values.

User avatar
wallarug
Posts: 460
Joined: Mon May 14, 2012 8:21 am
Location: Sydney, Australia

Re: Question about Atmel chip

Sun Oct 28, 2012 4:07 am

panik wrote:
wallarug wrote:I have read through some of the data sheets there but I cannot seem to find what I am looking for. All I would like is a basic summary that has the timer speeds for the Atmega328p running at [email protected] volts. All the information for Arduino Uno s are summarised nicely on the Arduino Forums and website for the 16Mhz Chip (http://www.arduino.cc/playground/Main/T ... Cheatsheet). I would like the same information for the chip on the Gertboard.
In the list on the page you link to, the <setting> part is how to set the prescaler to the value of the 'divisor', and is what's in bits CS02, CS01 and CS00, the 3 LSB (least significant) bits of register TCCR0B (in the case of TIMER0). Look for the correct bits to set on page 108-109, table 15-9 of the 'complete' datasheet.

Consider that: Frequency = F_CPU / prescaler / 256 (the time it takes for an 8 bit timer to wrap around.)

Take the first example on the page you link to, TIMER0 has a frequency of:
16000000 / 1 / 256 = 62500 (setting 0x01)
16000000 / 8 / 256 = 7812.5 (setting 0x02)
...
...
So far, those are the same values as on the cheat sheet.

For 12Mhz, those values would be:
12000000 / 1 / 256 = 46875 (setting 0x01)
12000000 / 8 / 256 = 5859.375 (setting 0x02)
...
...

I'm sure you'll be able to calculate the rest of the values.
Thank You @panik, this will be very helpful for me and others.
Just one other Question, how do you set the timer0 high than 62.5Khz (16MHz Core and 12MHz core). Some people have been using 64KHz frequency for motor controlling and I would like to do the same using PWM and AnalogWrite() function.

User avatar
panik
Posts: 369
Joined: Fri Sep 23, 2011 12:29 pm
Location: Netherlands

Re: Question about Atmel chip

Sun Oct 28, 2012 1:08 pm

wallarug wrote:Just one other Question, how do you set the timer0 high than 62.5Khz (16MHz Core and 12MHz core). Some people have been using 64KHz frequency for motor controlling and I would like to do the same using PWM and AnalogWrite() function.
For higher frequencies, I can only assume they're using the 'Fast PWM' mode. It involves setting the WGM01 and WGM00 bits of the TCCR0A register, and WGM02 of the TCCR0B register (see page 105-107, and also 'modes of operation' on page 99). I'd have to try it out to be more specific though.

Also note, that calculating the frequencies (above) is only for the 8 bit Timer0. Using the 16 bit timer for PWM is a bit more complicated. Again, have to try it out to be more specific. I think it's a pretty safe assumption that the frequencies on 12 Mhz are 75% of those on 16 Mhz, but I could be totally wrong.

User avatar
Gert van Loo
Posts: 2485
Joined: Tue Aug 02, 2011 7:27 am
Contact: Website

Re: Question about Atmel chip

Sun Oct 28, 2012 3:16 pm

Going to a high frequency is not always good.
I know that motor controller chips have a spec. which says what the maximum freuquency is.
The L6203 spec says typical 30KHz, max 100KHz.

User avatar
wallarug
Posts: 460
Joined: Mon May 14, 2012 8:21 am
Location: Sydney, Australia

Re: Question about Atmel chip

Sun Oct 28, 2012 9:11 pm

panik wrote:
wallarug wrote:Just one other Question, how do you set the timer0 high than 62.5Khz (16MHz Core and 12MHz core). Some people have been using 64KHz frequency for motor controlling and I would like to do the same using PWM and AnalogWrite() function.
For higher frequencies, I can only assume they're using the 'Fast PWM' mode. It involves setting the WGM01 and WGM00 bits of the TCCR0A register, and WGM02 of the TCCR0B register (see page 105-107, and also 'modes of operation' on page 99). I'd have to try it out to be more specific though.

Also note, that calculating the frequencies (above) is only for the 8 bit Timer0. Using the 16 bit timer for PWM is a bit more complicated. Again, have to try it out to be more specific. I think it's a pretty safe assumption that the frequencies on 12 Mhz are 75% of those on 16 Mhz, but I could be totally wrong.
I know that you calculate the frequency of the 16 bit timers by halving the amount again. eg. pre_scaler 1 on [email protected] is 62.5KHz. A pre_scaler of 1 in timer1 is going to equal 31.25KHz.

What I was wondering was how do I get out of these specs and into higher ones such as 64KHz. The Adafruit motor shield (which I don't own) seems to be able to get PWM frequencies as high as 64KHz. This seems to just be a function of the Atmega and not any extra hardware. How can I set PWM to 64KHz?

User avatar
panik
Posts: 369
Joined: Fri Sep 23, 2011 12:29 pm
Location: Netherlands

Re: Question about Atmel chip

Sun Oct 28, 2012 9:28 pm

If you do a search on the page you linked to for 'Fast PWM', there's useful info on the bottom half of the page.

User avatar
wallarug
Posts: 460
Joined: Mon May 14, 2012 8:21 am
Location: Sydney, Australia

Re: Question about Atmel chip

Mon Oct 29, 2012 6:08 am

Would:

Code: Select all

TCCR2B = TCCR2B & 0b11111000 | 0x01 ; //timer2 to 31.25KHz
TCCR0B = TCCR0B & 0b11111000 | 0x01 ;  //timer0 to 62.5Khz
TCCR2B = TCCR2B & 0b11111000 | 0x01 ; //timer1 to 31.25Khz
Set the frequencies I need with no modification to any files?

User avatar
wallarug
Posts: 460
Joined: Mon May 14, 2012 8:21 am
Location: Sydney, Australia

Re: Question about Atmel chip

Mon Oct 29, 2012 6:43 am

wallarug wrote:Would:

Code: Select all

TCCR2B = TCCR2B & 0b11111000 | 0x01 ; //timer2 to 31.25KHz
TCCR0B = TCCR0B & 0b11111000 | 0x01 ;  //timer0 to 62.5Khz
TCCR2B = TCCR2B & 0b11111000 | 0x01 ; //timer1 to 31.25Khz
Set the frequencies I need with no modification to any files?
I don't understand how the Adafruit motor shield can achieve frequencies of 64KHz?

User avatar
panik
Posts: 369
Joined: Fri Sep 23, 2011 12:29 pm
Location: Netherlands

Re: Question about Atmel chip

Mon Oct 29, 2012 7:45 pm

wallarug wrote:I don't understand how the Adafruit motor shield can achieve frequencies of 64KHz?
Look at: https://github.com/adafruit/Adafruit-Mo ... /AFMotor.h

Since nice, round numbers like 64, 8 and 1 are only found in the #defined names of the Motorshield library, I can only assume(* see disclaimer below) that those #defines are just used to 'pretty up' the code.

Example on lines 48-50, with the familiar CS00 and CS01 bits from the TCCR0B register (Timer 0):

Code: Select all

#define MOTOR34_64KHZ _BV(CS00)             // no prescale
#define MOTOR34_8KHZ _BV(CS01)              // divide by 8
#define MOTOR34_1KHZ _BV(CS01) | _BV(CS00)  // divide by 64
I assume(*) they're probably substitutes for the following values:
MOTOR34_64KHZ would be 62.5 KHz
MOTOR34_8KHZ would be 7.8125 KHz
MOTOR34_1KHZ would be 0.9765625 KHz

Further 'proof' on lines 72-76 (the PIC32-code):

Code: Select all

[...]
#define MOTOR12_19KHZ   4   // 1:16, actual frequency 19KHz
#define MOTOR12_8KHZ    5   // 1:32, actual frequency 9.7KHz
#define MOTOR12_4_8KHZ  6   // 1:64, actual frequency 4.8KHz
#define MOTOR12_2KHZ    7   // 1:256, actual frequency 1.2KHz
#define MOTOR12_1KHZ    7   // 1:256, actual frequency 1.2KHz
Also, remember these are values for MCU's running on 16 MHz, not 12 MHz as on the Gertboard.

(*) disclaimer: You know what people say about assuming things. I should know better, but I'm an idiot.

User avatar
wallarug
Posts: 460
Joined: Mon May 14, 2012 8:21 am
Location: Sydney, Australia

Re: Question about Atmel chip

Mon Oct 29, 2012 8:33 pm

So the only frequencies achievable are with the set pre scaler values.

Code: Select all

62500 Hz
31 250 Hz
....
If someone knows different, please let me know.

User avatar
wallarug
Posts: 460
Joined: Mon May 14, 2012 8:21 am
Location: Sydney, Australia

Re: Question about Atmel chip

Tue Oct 30, 2012 6:28 am

Here is the frequencies that I calculated for the 12 MHz clock of the PWM timers

Code: Select all

timer0 = 46 875 Hz  //Fast PWM  && Prescaler of "1"
timer1 = 23 437.5 Hz  //Phase corrected PWM && Prescaler of "1"
timer2 = 23 437.5 Hz  //Phase corrected PWM && Prescaler of "1"
Can someone confirm the above please.

Also, I think that Fast PWM can only be achieved on timer0...I am right?

Return to “HATs and other add-ons”