Unboxing and testing the Arduino Due

Talk about Arduino board, sheilds. Sharing Arduino projects, program, problems, solutions, suggestions..... many more, all are welcome.

Unboxing and testing the Arduino Due

Postby Brian Griffin » Tue Jan 08, 2013 3:07 pm

Here it is, the 32-bit Arduino, opened from the package.

arduinodue.jpg
Arduino Due


This is powered by Atmel's AT91SAM3X8E using ARM Cortex-M3 core, with an SD-Card control system and a multi-pipeline DMA controller. Plus, it has a lot of pins too, so you can interface with whatever things you want to do on it, like a small TFT screen or anything else.

For some of us who do like to make music - there is a 12-bit DAC on it. And there are other things in the Cortex-M3 which you can do faster signal processing inside.

I will be testing a bit of each feature on the system, so check back regularly. :)
PIC - UIC00B from Cytron (replacement for my broken PICKit 2), Pickit 3, MikroC for PIC
dsPIC - MikroC for dsPIC, mikromedia board (dsPIC33)
AVR - AVR Dragon
Parallax - Prop tool
User avatar
Brian Griffin
Enthusiast
 
Posts: 403
Joined: Mon Jan 17, 2011 9:36 am

ATSAM3X8E - Parallel I/O

Postby Brian Griffin » Wed Jan 09, 2013 12:42 am

I've just spent an hour reading the datasheet, and the header files in the folder "arduino-1.51r2\hardware\arduino\sam\system\CMSIS\Device\ATMEL\sam3xa\include". The registers are very different compared to the PIC32, where they have documented the registers in the PIC32 datasheet very clearly instead of just telling the address locations, which might be the case for the ATSAM3X8E processor in the Due.

So, stripping down to the bare minimum, I found out that if you need a bit more speed to access the pin I/O (most probably for dynamic pin-mapping for LCDs), you can directly access the registers instead.

CODE: SELECT_ALL_CODE
void setup() {
  // put your setup code here, to run once:
  REG_PIOD_PER = (1<<8);  // PIOD Enabled
  REG_PIOD_OER = (1<<8);  // PIOD output enable
  REG_PIOB_PER = (1<<27); // PIOB Enabled
  REG_PIOB_OER = (1<<27); // PIOB output enable
  REG_PIOB_CODR = (1<<27); // PIOB clear output register
}

void loop() {
  // put your main code here, to run repeatedly:
  REG_PIOD_SODR = 1<<8;   // Set output register (PWM12 pin on)
  delay(250);
  REG_PIOD_CODR = 1<<8;   // Clear output register (PWM12 pin off)
  delay(250); 
}


This code enables both PIOB and D on the Due, and turned to output modes in the setup function. The pin from PWM13 (PB27) is turned off, hence the 'L' LED on the board is not turned on. Meanwhile, in the loop, the pin from PWM12 is repeatedly cleared and switched on with delays of 250ms. (Of course, get a breadboard, some jumper wires, an LED, and a suitable resistor on this too...)

I haven't yet to read the interrupts and the timer parts. The datasheet for the Atmel microcontroller isn't too bad, provided if you read them one-by-one and not leaving out the other details.
PIC - UIC00B from Cytron (replacement for my broken PICKit 2), Pickit 3, MikroC for PIC
dsPIC - MikroC for dsPIC, mikromedia board (dsPIC33)
AVR - AVR Dragon
Parallax - Prop tool
User avatar
Brian Griffin
Enthusiast
 
Posts: 403
Joined: Mon Jan 17, 2011 9:36 am

ATSAM3X8E - Timer-Counter and Interrupts

Postby Brian Griffin » Thu Jan 10, 2013 3:18 pm

The more tricky part about handling ARM processors are the timer-counter modules and the interrupts themselves. They are not as direct as anything in the MPLAB XC32.

One more thing - if you need a direct manipulation of the I/O registers like what you usually do in PIC16/18F, please enable the respective I/O bit in the REG_PIOx_OWER (where the x is the port letter) register. Otherwise, writing and clearing the bit inside will not work.

The 'clearing of interrupt flags' is automatically handled - but you have to read the interrupt flag registers first, "REG_TC0_SR0".

CODE: SELECT_ALL_CODE
void TC0_Handler()
{
    long dummy=REG_TC0_SR0; // vital - reading this clears some flag
                            // otherwise you get infinite interrupts
    REG_PIOD_ODSR ^= (1<<8);
}

void setup() {
  // put your setup code here, to run once:
  REG_PIOD_PER = (1<<8);  // PIOD Enabled, Disable peripheral control of pin
  REG_PIOD_OER = (1<<8);  // PIOD output enable
  REG_PIOD_OWER = (1<<8); // PIOD Output Write Enable
  REG_PIOD_CODR = (1<<8);
 
  REG_PIOB_PER = (1<<27); // PIOB Enabled
  REG_PIOB_OER = (1<<27); // PIOB output enable
  REG_PIOB_CODR = (1<<27); // PIOB clear output register
 
  Timer1Setup();
}

void Timer1Setup() {
  // Channel 0, waveform mode
   REG_PMC_PCER0 = (1<<27); // Enable Peripheral clock on TC0
  REG_TC0_WPMR = 0x54494D00; // Write Protect Disabled.
  REG_TC0_IER0 = (1<<4);   // Interrupt at RC compare
  REG_TC0_IDR0 = ~(1<<4);  // Disable all interrupts except RC Compare
  //REG_TC0_CMR0 = 0x0000;
  REG_TC0_CMR0 = (1<<15) | (0x02<<13) | (0x03<<0); // WAVE = 1, WAVESEL = 10, TIMER_CLOCK4 = MCK/128
  REG_TC0_CCR0 = (1<<0) | (1<<2);
 
  REG_TC0_RC0 = 0x8000;
  NVIC_EnableIRQ(TC0_IRQn); 
}

void loop() {
  // put your main code here, to run repeatedly:
 
}


Prior to enabling the timer, the peripheral clock is disabled by default. You have to turn them on first, and then you can switch on the remaining TC registers.

This example code toggles the pin12 on the Due for every 50ms. It's a square wave, of course. The prescaler is 128 (84MHz/128) and the period to trigger the interrup is 32768 (REG_TC0_RC0). The maximum counter value is 0xffff only on that processor.

Since I have limited time to read the datasheet, I'll explain the rest later.

Reference: http://arduino.cc/forum/index.php?topic=130423.0
Attachments
NewFile0.jpg
waveform
NewFile0.jpg (25.56 KiB) Viewed 3447 times
PIC - UIC00B from Cytron (replacement for my broken PICKit 2), Pickit 3, MikroC for PIC
dsPIC - MikroC for dsPIC, mikromedia board (dsPIC33)
AVR - AVR Dragon
Parallax - Prop tool
User avatar
Brian Griffin
Enthusiast
 
Posts: 403
Joined: Mon Jan 17, 2011 9:36 am

Re: Unboxing and testing the Arduino Due

Postby ober » Fri Jan 11, 2013 9:31 am

well done, just to share the video we did for Arduino Due:
Ober Choo
Cytron Technologies Sdn Bhd
www.cytron.com.my
User avatar
ober
Moderator
 
Posts: 1486
Joined: Wed Apr 15, 2009 1:03 pm

Re: Unboxing and testing the Arduino Due

Postby shahrul » Fri Jan 11, 2013 3:11 pm

I just want to know, the speed which one faster Arduino Due or ChipKIT MAX32? If we do digitalWrite HIGH and LOW, which one faster? Because I already have ChipKIT MAX32.
User avatar
shahrul
Professional
 
Posts: 812
Joined: Sat May 16, 2009 9:54 pm
Location: Selangor

Re: Unboxing and testing the Arduino Due

Postby Brian Griffin » Fri Jan 11, 2013 4:41 pm

shahrul WROTE:I just want to know, the speed which one faster Arduino Due or ChipKIT MAX32? If we do digitalWrite HIGH and LOW, which one faster? Because I already have ChipKIT MAX32.


The Due uses ARM Cortex-M3 core, while the MAX32 (PIC32MX795F512) uses MIPS M4K core. Both of them have almost the same performance, with the slightly faster performance goes to the PIC32 (1.5 DMIPS/mhz) than the ARM Cortex-M3 (1.25 DMIPS/mhz). However, those are quite subjective and depends on the compiler and the applications of the system itself.

Therefore, the digitalWrite performance on both could be the same, or slightly different. If you need a faster write to the pins, you may need to directly access the registers inside, with reference to the datasheet and the pin connections in the respective prototyping systems like Arduino Due and Max32.
PIC - UIC00B from Cytron (replacement for my broken PICKit 2), Pickit 3, MikroC for PIC
dsPIC - MikroC for dsPIC, mikromedia board (dsPIC33)
AVR - AVR Dragon
Parallax - Prop tool
User avatar
Brian Griffin
Enthusiast
 
Posts: 403
Joined: Mon Jan 17, 2011 9:36 am

Re: Unboxing and testing the Arduino Due

Postby shahrul » Fri Jan 11, 2013 6:48 pm

Thanks Brian Griffin, you are the sifu in many microcontroller, :)
Yes, the performance also depends the software or compiler, how the software translating the code. I like to write directly to the pin address for faster process.
User avatar
shahrul
Professional
 
Posts: 812
Joined: Sat May 16, 2009 9:54 pm
Location: Selangor


Return to Arduino Based

Who is online

Users browsing this forum: No registered users and 16 guests

cron