Show Posts
Pages: 1 ... 10 11 [12] 13 14 ... 32
166  Products / Arduino Due / Re: Calculate the Root Mean Sqaure on: September 01, 2013, 08:51:12 am
Hello pedrolopes746,

Try this:

Code:
#define ARM_MATH_CM3
#include <arm_math.h>

float32_t data[5] = {1, 2, 3, 4, 5};
float32_t *d = data;
float32_t *pResult;

void setup() {

Serial.begin(9600);

}

void loop() {

arm_rms_f32(d, 5, pResult);

while(1){

}

}

void arm_rms_f32(
  float32_t * pSrc,
  uint32_t blockSize,
  float32_t * pResult)
{
  float32_t sum = 0.0f;                          /* Accumulator */
  float32_t in;                                  /* Tempoprary variable to store input value */
  uint32_t blkCnt;                               /* loop counter */

#ifndef ARM_MATH_CM0

  /* Run the below code for Cortex-M4 and Cortex-M3 */

  /* loop Unrolling */
  blkCnt = blockSize >> 2u;

  /* First part of the processing with loop unrolling.  Compute 4 outputs at a time.   
   ** a second loop below computes the remaining 1 to 3 samples. */
  while(blkCnt > 0u)
  {
    /* C = A[0] * A[0] + A[1] * A[1] + A[2] * A[2] + ... + A[blockSize-1] * A[blockSize-1] */
    /* Compute sum of the squares and then store the result in a temporary variable, sum  */
    in = *pSrc++;
    sum += in * in;
    in = *pSrc++;
    sum += in * in;
    in = *pSrc++;
    sum += in * in;
    in = *pSrc++;
    sum += in * in;

    /* Decrement the loop counter */
    blkCnt--;
  }

  /* If the blockSize is not a multiple of 4, compute any remaining output samples here.   
   ** No loop unrolling is used. */
  blkCnt = blockSize % 0x4u;

#else

  /* Run the below code for Cortex-M0 */

  /* Loop over blockSize number of values */
  blkCnt = blockSize;

#endif /* #ifndef ARM_MATH_CM0 */

  while(blkCnt > 0u)
  {
    /* C = A[0] * A[0] + A[1] * A[1] + A[2] * A[2] + ... + A[blockSize-1] * A[blockSize-1] */
    /* Compute sum of the squares and then store the results in a temporary variable, sum  */
    in = *pSrc++;
    sum += in * in;

    /* Decrement the loop counter */
    blkCnt--;
  }

  /* Compute Rms, store the result in the destination and print it */
  Serial.println(sqrt(sum / (float32_t) blockSize));
}

Output:

Quote
3.32

Regards!
167  Products / Arduino Due / Re: Reading the temperature sensor inside Arduino Due on: August 31, 2013, 10:16:13 pm
I run this as is with 1.5.3 and it only prints one value.
Any suggestions, please?

Hello garygid,

In order to synchronize the analog-to-digital conversions, the code needs to be interrupted and the ADC restarted every time the conversion ends. To do that, I forgot to tell that it is required to add few lines of code (an 'if') into the SysTick_Handler function inside the cortex_handlers.c source file.

The cortex_handlers.c file is located in the following path:

Quote
...\arduino-1.5.3-windows\arduino-1.5.3\hardware\arduino\sam\cores\arduino\

Thus, please, proceed to add the following 'if' into the SysTick_Handler at the top of the function as follows:

Code:
void SysTick_Handler(void)
{
if ((adc_get_status(ADC) & ADC_ISR_EOC15) == ADC_ISR_EOC15) {
adc_start(ADC);
}
if (sysTickHook())
return;

tickReset();

//Increment tick count each ms
TimeTick_Increment();
}

Doing the above change, your Due should start to show the values from the temperature sensor. Sorry for overlook that. Please, let me know how it goes. Regards!

EDIT: Remember to re-upload the code after the change. -P
168  Products / Arduino Due / Re: Arduino Due / Cross Compiler on: August 30, 2013, 07:31:03 pm
Hello dezguy,

As you are going to mess with the ASF, prepare to meet Atmel's hell.- I speak from my own experience. Too much junk code! It's like the Amazon rainforest. It's very easy to get lost in it. So far I have ported a couple of libraries from ASF to Due. A much better start to understand the SAM core is to get familiar with the Arduino libsam library.

Quote
...\arduino-1.5.2-windows\arduino-1.5.2\hardware\arduino\sam\system\libsam 

There you will find the source and include SAM drivers like ADC, PIO, PMC, RTC, TWI, etc. The duo Arduino-Atmel did a great job in it that deserves the benefit of a close look. Good luck!
169  Products / Arduino Due / Reading the temperature sensor inside Arduino Due on: August 29, 2013, 10:53:25 pm
Here my 'ported' raw code of the internal temperature sensor example from Atmel AS6 ASF. It run OK in my Due.
The temperature values match accurately the ones from the original code (Arduino Due/X). Despite the sensor it is not accurate (+-15%) it could be use as a warning if the SAM3X8E gets low-temps (~ -40 C)  or over-temps (~ +85 C). Anyway, a good start could be to calibrate your Due's sensor at ambient temperature, getting 0.8V and knowing that the temperature slope dVT/dT = 2.65 mV/C. I did the calibration in my Due, and around 25.5C in my room I got 800 of ul_value.(that's why my value in code line 44).

Code:
/** Example - ADC temperature sensor for Arduino Due. */

/** Size of the receive buffer and transmit buffer. */
#define BUFFER_SIZE     (100)
/** Reference voltage for ADC,in mv. */
#define VOLT_REF        (3300)
/** The maximal digital value */
#define MAX_DIGITAL     (4095)

void setup() {
Serial.begin(115200);
}

/** adc buffer */
static int16_t gs_s_adc_values[BUFFER_SIZE] = { 0 };
/** brief ADC interrupt that handles RXBUFF interrupt */
void ADC_Handler(void)
{
uint32_t ul_counter;
        int32_t l_vol;
        float f_temp;
        uint32_t ul_value = 0;
uint32_t ul_temp_value = 0;
if ((ADC->ADC_ISR & ADC_ISR_RXBUFF) == ADC_ISR_RXBUFF) {
        /* The destination buffer. */
        ADC->ADC_RPR = (uint32_t) gs_s_adc_values;
        /* The size of the buffer. */
        ADC->ADC_RCR = BUFFER_SIZE;
        /* enable transfer. */
ADC->ADC_PTCR = ADC_PTCR_RXTEN;
        /* Multisample. */
for (ul_counter = 0; ul_counter < BUFFER_SIZE; ul_counter++) {
         ul_value += gs_s_adc_values[ul_counter];
                }
                /* Averaging */
ul_temp_value = ul_value / 10;
ul_value = ul_value / 100;
ul_temp_value -= (ul_value * 10);
/* Round for last decimal */
if (ul_temp_value > 4) {
ul_value++;
}
l_vol = ul_value * VOLT_REF / MAX_DIGITAL;
                f_temp = (float)(l_vol - 800) * 0.37736 + 25.5;
                Serial.print("Temp: ");
                Serial.println(f_temp);
                }
}

void loop() {
        /* Enable ADC channel 15 and turn on temperature sensor */
        ADC->ADC_CHER = 1 << 15;
        ADC->ADC_ACR |= ADC_ACR_TSON;
        /* Enable ADC interrupt. */
        NVIC_EnableIRQ(ADC_IRQn);
        /* Start conversion. */
ADC->ADC_CR = ADC_CR_START;
        /* Enable PDC channel interrupt. */
        ADC->ADC_IER = ADC_ISR_RXBUFF;
while (1) {}
}

Regards!
170  Products / Arduino Due / Re: atmega16u2 bootloader not working on: August 29, 2013, 09:57:02 pm
Hello Aureliuss,

I regret that I cannot help you right now with your test. And may be you are already aware of this step-by-step tutorial from the Arduino team, but here the link just in case:

http://arduino.cc/en/Hacking/Upgrading16U2Due

Good luck!
171  Products / Arduino Due / Re: Arduino Due in sleep mode on: August 29, 2013, 08:52:28 am
Hello elnhege,

The sleep mode in the SAM3X8E (Arduino's Due MCU) as one of the three Low Power modes, it's based on the deep-sleep mode of its core(Cortex-M3). Its implementation is done in the PMC (Power Management Controller) register via Wait for Interrupt (WFI) or Wait for Event (WFE) instructions. There is also a deep sleep function using the SCR register. You can find information about this sleep mode in the doc11057.pdf, sections 5.5.1 and 12.8.

http://www.atmel.com/Images/doc11057.pdf

If you want to explore more the sleep mode functions in the Arduino Due library, you can check the pmc.c file (lines 972-982).

Quote
C:\Users\YourName\Downloads\arduino-1.5.2-windows\arduino-1.5.2\hardware\arduino\sam\system\libsam\source

Regards!
172  Products / Arduino Due / Re: ATmega16u2 Code on: August 29, 2013, 06:48:51 am
Hello CrazyCreator,

Please, check this reply #25 of this thread:
http://forum.arduino.cc/index.php?topic=134847.15

Regards!
173  Products / Arduino Due / Re: Serial.read problems with Arduino Due on: August 28, 2013, 09:02:48 pm
Hello giubio51,
Normally, when you wait for serial data is to read it, but if you only want to write 'W' each time a character is sent via serial, a good way to empty Serial.available() is using Serial.read()as follows:

Code:
//******************************************************************************************
// Setup (executed only one time
//******************************************************************************************
void setup(void)
{
  Serial.begin(9600);         // Baud Rate test may values as 1200, 115200, 9600 etc..., no one works
  while (!Serial);
  pinMode(13,OUTPUT);    // This pin is ON at power on (?) and it goes on every time I send a byte with the PC, I can reset it via pin input 10
  pinMode(10,INPUT);       // Just for test, used to resetpin output 13 (led) that is on by it self (?)
  Serial.print("K");            // This print is in setup loop, then sent only one time, but it appears time by time when I send bytes from the PC
  Serial.flush();       
}

//******************************************************************************************
// Main Loop
//******************************************************************************************
void loop(void)
{
  if(Serial.available() >0)
  {
    Serial.read();
    Serial.print("W");
    delay(200);
  }
  if (digitalRead(10) == 0) {digitalWrite(13,0);}
  delay(100);
}

Regards!
174  Products / Arduino Due / Re: __attribute__((packed)) is failing in Arduino 1.5.2 IDE (On Due board) on: August 28, 2013, 07:30:06 pm
Yep. Compilation without complaints. I know what that means. I also do not imagine myself crafting my code with asserts trying to catch layout errors only because my program misbehaves at run time. It's like chasing the white rabbit. That has been always the thing with C/C++ compilers. They are like old blind and mute Lamas to whom we must be attentive, in silence, waiting for any sign like: error 0x45AC00000 ITIPHHTEMETEIROEBE. Regards! 
175  Products / Arduino Due / Re: __attribute__((packed)) is failing in Arduino 1.5.2 IDE (On Due board) on: August 27, 2013, 09:30:24 pm
Hello haturi,
I think you are facing a syntax issue. Here the corrected code:

Code:
void setup() {
  // put your setup code here, to run once:
typedef struct __attribute__((packed)) quest_st
{
    uint32_t    kern;
    uint8_t     chCount;

    union
    {
        uint8_t asAmpli;
        struct
        {
            uint8_t dir   : 4;
            uint8_t curve : 4;
        };
    } uAmpli;

    union
    {
        uint8_t asForce;
        struct
        {
            uint8_t amount  : 5;
            uint8_t axis    : 3;
        };
    } uForce;
   
}   QUEST;

int  ss;
QUEST myQuest;
char buf[ 80];
 
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  Serial.println("Program start.");
  delay(200);

  if( &ss != NULL)
    ss = sizeof( QUEST);
  sprintf( &buf[0], "\n sizeof( QUEST) = %ld  sizeof(myQuest) = %ld"
    "  sizeof( struct quest_st) = %ld", ss, sizeof( myQuest), sizeof( struct quest_st));
  Serial.println( &buf[0]); 
}

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

Output:
Quote
Program start.

 sizeof( QUEST) = 7  sizeof(myQuest) = 7  sizeof( struct quest_st) = 7

Regards!
176  Products / Arduino Due / Re: Is bossac checking the CIDR of the arduino DUE on: August 27, 2013, 12:00:15 pm
Hello kingmail,
Bossac is not only a boot-loader tool for the SAM3X8E but supports all of Atmel's known flash-based SAM devices. I believe bossac checks automatically the CIDR of the MCU. Just try:

Quote
bossac.exe --port=COM1 -U true -i

I used comm. port 1 as an example. Remember to change to your current COM port.
Also change to 'false' if your are connecting to the USB-to-TTL serial chip.

You should program your sam3x8c using bossac in the same way you do it for Arduino Due.
Anyway, I have a 3x8c system at home and I can try some tests tonight.

Regards!

EDIT:
<< Do not use the Arduino IDE to compile/program your SAM3X8C based board at least you have the variant files redefined for the 100-pin package of SAM3X8c. I am not sure about the uart interface settings but may be you will need to redefine them too.
I would recommend you to use Atmel Studio 6.1 where you can create bare minimum project templates for the SAM3X8C which will automatically generates the 100-in/out pins and other utily files. Just let me know where you are in your project (stage).
You can always count with the at91 Atmel tech support team after generate a ticket. >>
177  Products / Arduino Due / Re: Arduino Due and ADK 2012 on: August 26, 2013, 03:05:50 pm
DO NOT connect directly your speaker to the DAC pin.
Please, read and follow the following updated tutorial.

http://arduino.cc/en/Tutorial/SimpleAudioPlayer

Regards!
178  Products / Arduino Due / Re: Why the sketch size and amount of RAM used by DUE is more than MEGA. on: August 26, 2013, 10:16:11 am
Give their different MCU's, Due (32-bit Cortex-M3 based SAM3X8E) and Mega ( 8-bit AVR RISC ATmega2560), they use a different version of the same programming GNU tool chain (compiler, liker, additional utilities). AVR for Mega and ARM-none-eabi for Due, which means that the coding is also different. 32-bit vs 8-bit program instructions and memory locations means also different coding sizes. Regards! 
179  Products / Arduino Due / Re: Another I2C Thread on: August 24, 2013, 05:59:41 pm
Hi Guy,

I know there are several post about using the I2C bus on the DUE however; there doesn't seem to be a clear answer...

Has anyone managed to get any I2C device to work on the DUE yet?

Hello adamatcooranbong,

Above all, I am very happy you mentioned the I2C and Due. You are rigth about certain confusion about re-conciliate them. Indeed, I was encouraged by some friends to start a new post here trying to present a simple method about how to interconnect Due with some I2C device.

I take the advantage to clarify that regarding the Philips' bus, from the Arduino Due point of view, we talk about TWI (Two-wire Interface) instead of I2C. Due's microcontroller (SAM3X8E) has two TWI interfaces that are fully compatible with the I2C devices with some exceptions like: the START BYTE and Slope control and input filtering, AFAIK, are not supported by Due. Also, these two TWI buses keep the same pin names (SDA)(SCL)(SDA1)(SCL1).

Which is more important, there is a very good TWI library (around 20 functions) for Due and several examples (i.e. digital_potentiometer) that could help to understand better how Due works interfacing I2C devices. I believe it is more about to play with it.

If you have a I2C device you want to connect with Due, please, let me know about it and I believe we can make them work together. Regards!
180  Products / Arduino Due / Re: Internal RTC with back up battery on: August 23, 2013, 04:30:20 pm
Could you show the connection between power supply (3.3v), backup battery and VDDBU pin? Thanks.
Pages: 1 ... 10 11 [12] 13 14 ... 32