Show Posts
Pages: 1 2 3 [4] 5
46  Products / Arduino Due / Re: DUE PWM Frequency on: January 16, 2013, 11:58:32 am
Hello,

I have fixed the problem, somewhat.

Looking into variant.cpp

Code:
  { PIOB, PIO_PB25B_TIOA0,   ID_PIOB, PIO_PERIPH_B, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_TIMER), NO_ADC, NO_ADC, NOT_ON_PWM,  TC0_CHA0     }, // TIOA0
  { PIOC, PIO_PC28B_TIOA7,   ID_PIOC, PIO_PERIPH_B, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_TIMER), NO_ADC, NO_ADC, NOT_ON_PWM,  TC2_CHA7     }, // TIOA7
  { PIOC, PIO_PC26B_TIOB6,   ID_PIOC, PIO_PERIPH_B, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_TIMER), NO_ADC, NO_ADC, NOT_ON_PWM,  TC2_CHB6     }, // TIOB6

  // 5
  { PIOC, PIO_PC25B_TIOA6,   ID_PIOC, PIO_PERIPH_B, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_TIMER), NO_ADC, NO_ADC, NOT_ON_PWM,  TC2_CHA6     }, // TIOA6
  { PIOC, PIO_PC24B_PWML7,   ID_PIOC, PIO_PERIPH_B, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM),   NO_ADC, NO_ADC, PWM_CH7,     NOT_ON_TIMER }, // PWML7
  { PIOC, PIO_PC23B_PWML6,   ID_PIOC, PIO_PERIPH_B, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM),   NO_ADC, NO_ADC, PWM_CH6,     NOT_ON_TIMER }, // PWML6
  { PIOC, PIO_PC22B_PWML5,   ID_PIOC, PIO_PERIPH_B, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM),   NO_ADC, NO_ADC, PWM_CH5,     NOT_ON_TIMER }, // PWML5
  { PIOC, PIO_PC21B_PWML4,   ID_PIOC, PIO_PERIPH_B, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM),   NO_ADC, NO_ADC, PWM_CH4,

Notice that only pins 7, 6, 5 and 4 respond to the #define in the variant.h file.  I am not sure how to configure the rest of the pins to act accordingly.  I havent tried changing NOT_ON_PWM (highlighted in the other pin configurations) to PWM_CH#, if this is possible.  I am assuming the architecture allocates pins 2-13 as PWM pins but on 5-7 as reconfigurable PWM pins.

If anyone would like to contribute why/how to reconfigure other pins - that would be helpful.

Daniel

47  Products / Arduino Due / Re: DUE PWM Frequency on: January 15, 2013, 12:07:24 pm
Quote
You have to restart the IDE if you make changes to the underlying libraries as they are compiled only once for the sketch "to save time". 

you might look at PWMC_ConfigureClocks()

Hello,

I restarted my IDE to let it recompile, but I am still getting 1KHz PWM frequency, also I put the following line into setup but that did not do anything.

PWMC_ConfigureClocks(3922 * PWM_MAX_DUTY_CYCLE , 0, VARIANT_MCK);. 

I wouldn't prefer either way since this micro is designated for motor control, if anything I would like to strictly change the variable in variant.h - if you know any reason why it is still not change, I would much appreciate it.

Daniel

48  Products / Arduino Due / Re: DUE PWM Frequency on: January 10, 2013, 03:52:17 pm
Has anyone found a solid way (preferably in sketch) to modify the output PWM frequency?  Also changing variant.h from 1k to what ever you want isnt working for me.  Changing it and saving doesn't change the output frequency.

Daniel
49  Using Arduino / Project Guidance / Oscilating Motor Instability on: January 10, 2013, 03:37:58 pm
Hello,

I am controlling a motor using a PID controller and a master and slave quadrature encoder on a DUE.  When the error between master and slave become greater than 255, my motor cannot read steady states and oscillates. One way I have figured out to solve this is essentially never letting the error go up 255 by incrementing encoder counts by decimals.  Doing this makes my control very slow - It will take many revolutions in my master side to complete my slave side.

I tried tuning and changing encoder counts.. I am wondering if people have clues and suggestions?

Code:
/*
Project:
Name: Daniel G
Date: 10/15/2012
Company: RRI
*/

/*
EnA  |  In1  |  In2  |  Description
-----------------------------------------------
 0   |   X   |   X   |  Free Running Motor Stop
 1   |   1   |   0   |  Forward
 1   |   0   |   1   |  ReverslaveEncoder
 1   |   1   |   1   |  Fast Motor Stop
-----------------------------------------------

CHA: ____EEEE____EEEE____EEEE____EEEE
CHB: EE____EEEE____EEEE____EEEE____EE
When CHA rislaveEncoders check the state of CHB.  From here you can determine the
direction of the encoder corresponding to the Master or Slave
*/

#include <stdio.h>

int In1 = 8;         
int In2 = 9;         
int EnA = 10;         
int Master_CHA = 2;   // Interrupt INT0 on Pin 2    0
int Master_CHB = 4;   //
int Slave_CHA = 3;    // Interrupt INT1 on Pin 3   1
int Slave_CHB = 6;    //

int Master_CHB_val = 0;
int Slave_CHB_val = 0;
volatile float masterEncoder = 0;
volatile float slaveEncoder = 0;

// Control Signal and Error
float u = 0;
float err = 0;

// PID Control
int Kp = 10;
double Ki = .008;
double Kd = 0.2;

// Error Variables
float err_old = 0;
float err_intgrl = 0;
float err_dot = 0;
int max_int = 255;
int max_der = 255;

void setup()
{
  Serial.begin(115200);
  // slaveEncodertting Motor Pins
  pinMode(In1, OUTPUT); // Setting In1 (direction indicator)
  pinMode(In2, OUTPUT); // Setting In2 (direction indicator)
  pinMode(EnA, OUTPUT); // Setting PWM output
 
  // Set Encoder Pins & Interrupt
  pinMode(Master_CHB, INPUT);
  pinMode(Slave_CHB, INPUT);
  attachInterrupt(Master_CHA, Master_checkDirection, RISING); // CHA causes interrupt service routine
  attachInterrupt(Slave_CHA, Slave_checkDirection, RISING);   // CHA causes interrupt service routine
//  PWMC_ConfigureClocks(4000 * PWM_MAX_DUTY_CYCLE , 0, VARIANT_MCK);
 // TCCR1B = TCCR1B & 0b11111000 | 0x02; // PWM frequency changed from 500Hz to 3.922KHz - L298 typically can support 25KHz.
}

// ISR for Master (Controller)
void Master_checkDirection()
{
  Master_CHB_val = digitalRead(Master_CHB);        // When CHA RAISES check CHB
  if (Master_CHB_val == 0)  masterEncoder += 0.1;    // Increment Master count for a direction
  else masterEncoder -= 0.1;                         // Decrement Master count for the other direction   
}

// ISR for Slave (Motor)
void Slave_checkDirection()
{
  Slave_CHB_val = digitalRead(Slave_CHB);           // When CHA RAISES check CHB
  if (Slave_CHB_val == 0)  slaveEncoder += 0.1;    // Increment Slave count for a direction
  else slaveEncoder -= 0.1;                        // Decrement Slave count for the other direction
}

// Function to Set Direction of PWM
void setDirection(boolean In1_State, boolean In2_State)
{
  digitalWrite(In1, In1_State);
  digitalWrite(In2, In2_State);
}

void loop()
{
  err = slaveEncoder - masterEncoder;
 
  err_dot = err - err_old;
  err_dot = constrain(err_dot, -max_der, max_der);

  err_intgrl = err + err_intgrl;
  err_intgrl = constrain(err_intgrl, -max_int, max_int);
 
  u = float(Kp*err + Kd*err_dot + Ki*err_intgrl);
  u = constrain(u, -255, 255);
 
  if (u < 0)  {setDirection(LOW, HIGH);  u = -u;}
  else  setDirection(HIGH, LOW);
 
  analogWrite(EnA, u); // Write PWM value as the encoder count of the Master (controller)
 
  err = err_old;
  Serial.print(masterEncoder);
  Serial.print("|");
  Serial.print(slaveEncoder);
  Serial.print("|");
  Serial.println(u);
}
50  Using Arduino / Storage / Re: SD.open Returning 0 on: December 10, 2012, 11:17:08 am
The SD Card works just fine, but I realized that I was using the wrong library.  I need to be using SdFat, it is very robust so I hope to understand this quickly, thank you for your help.

Daniel
51  Using Arduino / Storage / Re: SD.open Returning 0 on: December 10, 2012, 10:31:21 am
PaulS,

Thank you for your help, I will do the changed and test the SD card alone - I contacted the manufacturer and the shield should be okay for the HCSD I am using.  The shield I am using is below:

http://arduino-direct.com/sunshop/index.php?l=product_detail&p=290

Sorry for such a late reply - I have been really sick with the flu.

Daniel

52  Using Arduino / Storage / Re: SD.open Returning 0 on: November 29, 2012, 06:02:47 pm
PaulS, sorry about that - I have a poor tendancy leaving it out.

Code:
#include <Wire.h>
#include <I2C_Anything.h>
#include <LiquidCrystal.h>
#include <SD.h>

int CS_PIN = 10;

LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

const byte MY_ADDRESS = 42;

float REFRESH_RATE = 0.0;
long ID = 1;

void setup()
{
  Serial.begin(9600);
  Wire.begin(MY_ADDRESS); 
  Wire.onReceive(receiveEvent);
 
  lcd.begin(16,2);
  pinMode(CS_PIN, OUTPUT);
 
  lcd.setCursor(0,0);
  lcd.print("ME: ");
  lcd.setCursor(8,0);
  lcd.print("SE: ");
  lcd.setCursor(0,1);
  lcd.print("Datalog: ");
 
  if (!SD.begin(CS_PIN))
  {
    Serial.println("Card Failure");
    return;
  }
  Serial.println("Card Ready");
}

volatile boolean haveData = false;
volatile int X;
volatile int Y;
int LOOP_COUNTER = 0;

void loop()

  if (haveData)
  {
    lcd.setCursor(3,0);
    lcd.print(X);
    lcd.setCursor(11,0);
    lcd.print(Y);
    haveData = false;   
  }
 
  File dataFile = SD.open("LOG.csv", FILE_WRITE);
 
  if (LOOP_COUNTER == 500)
  {
    if (dataFile)  <--- always prints 0
    {
      dataFile.print(millis());
      dataFile.print(", ");
      dataFile.print(ID);
      dataFile.print(", ");
      dataFile.print(X);
      dataFile.print(", ");
      dataFile.println(Y);
      dataFile.close();
      lcd.setCursor(9,1);
      lcd.print("Success");
      ID++;
    }
    else
    {
      lcd.setCursor(9,1);
      lcd.print("Failure");
    }
   
  LOOP_COUNTER = 0; 
 
  }   
  LOOP_COUNTER++;
}



void receiveEvent (int howMany)
{
  if (howMany >= (sizeof X) + (sizeof Y))
  {
    I2C_readAnything (X);
    I2C_readAnything (Y);
    haveData = true;
  }
}
53  Using Arduino / Storage / SD.open Returning 0 on: November 29, 2012, 01:28:55 pm
Hello,

I have a datalogging + LCD stacking shields and I am providing signals to store in a SD card (SDHC 16gb SanDisk Extreme Pro).  My code checks and returns a success when SD.begin() is sent.

But when I create an object and try to open open it.

Code:
File dataFile = SD.open("LOG.csv", FILE_WRITE);

I keep getting a 0 and I cannot open the SD card.

Any suggestions?
54  Using Arduino / Networking, Protocols, and Devices / Re: 2 Arduinos ... SD Shield Datalogging ... Speed on: November 16, 2012, 12:38:17 pm
Sorry for the vague explaination.

As it stands the Arduino only has 2 INT pins which I am using for the master and slave encoder pulses (using attachinterrupt()).  This is too control 1 motor.  Eventually I will go into more motors for more DOFs but that will require a different micro (but for now, this will suffice).  I am reading over fat16lib's work and I will be using that library to data log.  But for the sake of speed, I would like the data logging to be done a different arduino (for now).  So I was just wondering what methods I can use to transfer data from one arduino to another. 

Doing some tests and research, I would be happy with approximately 500Hz data logging, so I would need to reach the appropriate kbps speed for transfer.  Can serial communication be enough between the arduinos? SPI?

Daniel

55  Using Arduino / Networking, Protocols, and Devices / Re: 2 Arduinos ... SD Shield Datalogging ... Speed on: November 15, 2012, 02:20:40 pm
Okay, thank you for clearing that up.

Regarding my application, would there be a more efficient way?

Daniel
56  Using Arduino / Networking, Protocols, and Devices / Re: 2 Arduinos ... SD Shield Datalogging ... Speed on: November 15, 2012, 01:39:24 pm
Quote
My plan is to use the flash on the DAQ Arduino as a buffer
Cannot be done, falsh is unwritable runtime, use RAM

Can you not point to addresses in the flash and write to them?
57  Topics / Robotics / Re: Large Error Instability on: November 15, 2012, 01:35:01 pm
Even with Kp, I am experiencing this problem.  I do not think it has something to do with my PID parameters.  I personally think it has something to do with the scaling between master and slave.  The gearhead on the motor has a reduction radio of 377:1 while my master is 1:1.  This difference in scales (I believe) should cause some issue.

But, I also feel it could be ISR and floating point math - because even with a scaling ratio the PWM shouldn't go on to infinite.

In regards to your question, "How many pulses per second are you expecting?" I believe that is coming from the large amount of pulses from the slave end with the gearbox.  Because of the gearbox, there are tons of pulses coming in - especially when the motor exceeds maximum speed.

This is unnecessary frustration smiley-sad

Daniel

EDIT: johnwasser, maximum PWM signal is given (100%) - as this happens when the err goes through the roof.  I get pulses coming back at ~43Khz.  The Arduino should be able to process the ISR at this frequency, can it not?  Perhaps givening maximum PWM signal produces too quick of a interupt frequency in which the processor cannot keep up?

58  Using Arduino / Networking, Protocols, and Devices / Re: 2 Arduinos ... SD Shield Datalogging ... Speed on: November 15, 2012, 01:21:56 pm
Quote
send data from the DAQ Arduino to my data logging/LCD Arduino via SPI?
depends on the pins used by the data logging and who will be the master - I assume the data logging Arduino should be as she has 2 'devices'

Arduino1 will be doing acquisition and send information to Arduino2 when Arduino2 will be logging onto SD.  From this structure, I assume Arduino1 is the master.

Quote
Quote
My plan is to use the flash on the DAQ Arduino as a buffer
Cannot be done, falsh is unwritable runtime, use RAM
Yes, I was reading about it earlier and you are right, I am going to utilize the RAM.

Quote
Can you tell about the sensor used, the frequency and the data size of one sample?
Maybe tell us the goal of the project, there might be other ways too

It is a robotics project.  The "sensors" are quadrature encoders of a master/slave setup.  I would like to datalog onto an SD card.  I do not want the robotic controller wasting cycles data logging, so Id prefer using the RAM to hold and shoot data into another Arduino which will be doing the data logging. Regarding SD logging frequency, I dont mind a couple hundred Hz. 

Until I get my DUE this will have to suffice.

Daniel


59  Using Arduino / Networking, Protocols, and Devices / 2 Arduinos ... SD Shield Datalogging ... Speed on: November 15, 2012, 11:29:40 am
Hello,

My project embodies two Arduino UNOs.  One of which is purely data acquisition and one of which will be performing data logging and LCD display. I was wondering if it is possible to send data from the DAQ Arduino to my data logging/LCD Arduino via SPI? 

My plan is to use the flash on the DAQ Arduino as a buffer and flush the data time to time to the data logging Arduino (like a queue). I feel this will allow the maximum throughput of data. Hopefully I can reach up to a few KHz.

Your thoughts? Suggestions?

Daniel

60  Topics / Robotics / Re: Large Error Instability on: November 14, 2012, 01:41:39 pm
Notice below the err values are just fine when I move slowly, but applying a large instantaneous motion to my masterEncoder (essentially a step response).  The err builds up exponentially starting at -12668.67.

Code:
-6.23
-1.12
-1.12
-1.12
6.37
6.96
2.14
-5.98
-0.60
8.68
15.87
5.08
-2.71
-3.31
-1.20
0.60
4.20
7.80
5.70
-0.30
-0.30
-0.30
-1.80
-1.80
-2.10
-5.70
-12.01
-11.12
6.57
-4.51
-11.69
-9.27
-8.96
-0.85
-0.85
-0.85
-35.35
-12668.67
-25233.88
-33518.90
-42608.51
-52169.74
-61758.05
-71490.49
-81504.08
-91523.61
-101471.30
-111362.58
Pages: 1 2 3 [4] 5