Loading...
  Show Posts
Pages: [1] 2 3 ... 10
1  Using Arduino / Programming Questions / Re: Millis Accuracy Again on: April 19, 2013, 04:17:39 am
Hi orly_andico

I think it's a software related problem. You are doing some strange things with millis()...

I guess this is your loop:
Code:
void loop() {  
  long tstart = exttimer_millis();

  handler_called++;

  if ((handler_called % THINKPERIOD) != 0) {
    do_autoguider();
  }
  else {
    handler();
  }

  long tcnv = (exttimer_millis() - tstart) + 1;

  if (tcnv < PERIODMILLIS) {
    delay(PERIODMILLIS - tcnv);
  }
}

a delay in main loop and an incremente to keep track of when to do things. That is not how I would have done it.

Code:
void exttimer_init() {
  Timer1.initialize(10000);    // 10 milliseconds
  Timer1.attachInterrupt(exttimer_callback);
}

void exttimer_callback() {
  _mymillis += 10;
}

The exttimer has a resolution of 10 ms. That is alot considering you wanna do tcnv average here:
Code:
void read_encoder(long &A, long &B, long &tcnv) {
  int reading;
  int i;

  long t0, t1;

  t0 = exttimer_millis();

  // this should finish in 5ms or less @ 32ksps
  for (i = 0; i < OVERSAMPLING; i++) {
    reading = read_adc(1);
    A += reading;

    reading = read_adc(2);
    B += reading;
  }

  A = A / OVERSAMPLING;
  B = B / OVERSAMPLING;

  t1 = exttimer_millis();
  
  // tcnv should be in milliseconds
  tcnv = (t0 + t1) / 2;
}

Byt the way. You average calculation is a disaster just waiting to happpen. What happens if you forget to set the variables that &A and &B is refering to to not 0 prior to calling the routine..... strange average .....
Edit: This is happening in the calibrate() where encoderA and encoderB is set to 0 outside the while loop.

Btw, can you pleast explane how the calibrate() routine works. It seemes like a strange way to get the mean values from the encoders and keep the outliers out. It dos not follow dixon's test for outliers.

edit,edit: I have been thinking a but more about that calibration. I think you need to rethink it. You are oversampling from the encoders 64 times and then returning the average as reading value. If this value is an outlire then numerious of the 64 readings must be outliers. You should test for outliers among the crude values returned from the encoders.

-Fletcher
2  Using Arduino / Programming Questions / Re: oil heater in greenhouse on: April 17, 2013, 04:31:28 pm
Hi brygmester

Why do you want the heater (ovn) to go on/off every 250ms. The relay is going to go click, click, click, click every second. The latency time (dødtid) in your system is going to far higer than that so why not keep the on/off cycles much higher when you are in the temperature regon where you wanna heat the greenhouse.

It seems like a strange way to lower the heat output to 50% of nominel capacity.

-Fletcher
3  Using Arduino / Programming Questions / Re: Why won't this convert properly?! It is driving me maddddd on: April 12, 2013, 10:48:11 am
Hi

Quote
BTW, what I'm trying to do basically... is count up in binary... to get this pattern:
00000001
00000011
00000111
00001111
00011111
00111111
01111111
11111111

How about this:

Code:
void setup(){
  Serial.begin(115200);
  int lines=8;
  int number=1;
 
  for (int s=lines-1;s>=0;s--){
    for (int t=lines-1;t>=0;t--){
      Serial.print(bitRead(number,t));
    }
    Serial.println();
    number<<=1;  // bitshift number one to the left
    number+=1;   // add 1 to the right most bit
  }
}

void loop(){}

Output:
00000001
00000011
00000111
00001111
00011111
00111111
01111111
11111111


-Fletcher
4  Community / Bar Sport / Re: Ardunio C++ SUCKS!!!! on: August 03, 2012, 09:27:52 am
It was a base safe code .....  smiley-grin

Would be better to change:
Code:
Serial.println("Starting");
    running = 0;

Into:
Code:
Serial.println("Starting");
    running = 1;
too smiley-razz

-Fletcher
5  Community / Bar Sport / Re: Ardunio C++ SUCKS!!!! on: August 03, 2012, 05:03:19 am
Less talk - more action.

Quote
The main program is in a loop looking for a start switch closure. It then calls a custom function (I guess that is a C++ subroutine??) that looks for one of four detector triggers or a stop switch closure, in a loop. Each detector trigger calls one of two different custom functions to energize and de-enrgize some relays. It then returns to the detection process. It only returns to the startup loop if it finds a stop switch closure in the detection process.

I dont's have Arduino, realys, switches at me ... but I did have 8 min left of my lunchbreak.
Code:
const int startSwitch = 12;  // Start switch
const int stopSwitch = 11;   // Stop switch
const int det1 = 10;
const int det2 = 9;
const int det3 = 8;
const int det4 = 7;

boolean running = 0;

void setup(){
  pinMode(startSwitch, INPUT);
  digitalWrite(startSwitch, HIGH);  // enable pull-up
  pinMode(stopSwitch, INPUT);
  digitalWrite(stopSwitch, HIGH);  // enable pull-up
  pinMode(det1, INPUT);
  digitalWrite(det1, HIGH);  // enable pull-up
  pinMode(det2, INPUT);
  digitalWrite(det2, HIGH);  // enable pull-up
  pinMode(det3, INPUT);
  digitalWrite(det3, HIGH);  // enable pull-up
  pinMode(det4, INPUT);
  digitalWrite(det4, HIGH);  // enable pull-up
  
  Serial.begin(115200);
}

void loop(){
  if (digitalRead(startSwitch) == LOW){  // Is it time to start?
    Serial.println("Starting");
    running = 0;
  }
  while (running){
    if (digitalRead(det1) == LOW){action1;}
    if (digitalRead(det2) == LOW){action2;}
    if (digitalRead(det3) == LOW){action3;}
    if (digitalRead(det4) == LOW){action4;}
    if (digitalRead(stopSwitch) == LOW){  // Is it time to stop?
      Serial.println("Stopping");
      running = 0;
    }
  }
}

// ****
void action1(){
  Serial.println("Action 1");
  delay(1000);
}

void action2(){
  Serial.println("Action 2");
  delay(1000);
}

void action3(){
  Serial.println("Action 3");
  delay(1000);
}

void action4(){
  Serial.println("All your base are belong to us");
  delay(1000);
}

Compiled but NOT testet.

-Fletcher

Edit: This code works as intended:
Code:
const int startSwitch = 12;  // Start switch
const int stopSwitch = 11;   // Stop switch
const int det1 = 10;
const int det2 = 9;
const int det3 = 8;
const int det4 = 7;

boolean running = 0;

void setup(){
  pinMode(startSwitch, INPUT);
  digitalWrite(startSwitch, HIGH);  // enable pull-up
  pinMode(stopSwitch, INPUT);
  digitalWrite(stopSwitch, HIGH);  // enable pull-up
  pinMode(det1, INPUT);
  digitalWrite(det1, HIGH);  // enable pull-up
  pinMode(det2, INPUT);
  digitalWrite(det2, HIGH);  // enable pull-up
  pinMode(det3, INPUT);
  digitalWrite(det3, HIGH);  // enable pull-up
  pinMode(det4, INPUT);
  digitalWrite(det4, HIGH);  // enable pull-up
  
  Serial.begin(115200);
}

void loop(){
  if (digitalRead(startSwitch) == LOW){  // Is it time to start?
    Serial.println("Starting");
    running = 1;
  }
  while (running){
    if (digitalRead(det1) == LOW){action1();}
    if (digitalRead(det2) == LOW){action2();}
    if (digitalRead(det3) == LOW){action3();}
    if (digitalRead(det4) == LOW){action4();}
    if (digitalRead(stopSwitch) == LOW){  // Is it time to stop?
      Serial.println("Stopping");
      running = 0;
    }
  }
}

// ****
void action1(){
  Serial.println("Action 1");
  delay(1000);
}

void action2(){
  Serial.println("Action 2");
  delay(1000);
}

void action3(){
  Serial.println("Action 3");
  delay(1000);
}

void action4(){
  Serial.println("All your base are belong to us");
  delay(1000);
}
6  Using Arduino / Programming Questions / Re: retrieve last sent byte over serial on: August 03, 2012, 02:47:27 am
Hi Aconolly

Store values in EEPROM and read from EEPROM during startup.

http://arduino.cc/en/Reference/EEPROM

-Fletcher
7  Using Arduino / Programming Questions / Re: Uploading to What? How to clear? on: August 03, 2012, 02:35:55 am
Code:
void setup(){}
void loop (){}

-Fletcher
8  Using Arduino / Programming Questions / Re: problem with micros() on: August 01, 2012, 02:35:29 pm
Quote
This comes up about twice a month on the forum. The general answer is "you don't". How often do you reset your watch? Practically never, right? That's how often you should be trying to reset the Arduino's timers.

Truth about Arduino:
Anyone who ask:
How can I reset mills or timers?
Does not need the true answer.

By the way wife highjacked the TV so I got this code working:

Code:
const int ScreenPin1 = 11;
const int ScreenPin2 = 12;
const float dist = 1.0;     // Distance between 1 and 2 [ft]

unsigned long time1, time2, deltaTime;
float flySpeed;
boolean running = 0;

void setup(){
  pinMode(ScreenPin1, INPUT);
  digitalWrite(ScreenPin1, HIGH);
  pinMode(ScreenPin2, INPUT);
  digitalWrite(ScreenPin2, HIGH);
  Serial.begin(115200);
  Serial.println("Starting");
}

void loop(){
  if (!running && (digitalRead(ScreenPin1)) == LOW) {
    time1 = micros();
    running = 1;
  }
  if ((running && (digitalRead(ScreenPin2)) == LOW)) {
    time2 = micros();
    deltaTime = time2-time1;
    Serial.print("Time: ");
    Serial.print(deltaTime);
    Serial.println(" us");
   
    flySpeed = dist*1000000UL/deltaTime;
    Serial.print("Speed: ");
    Serial.print(flySpeed);
    Serial.println(" fps");
    Serial.println();
    running = 0;
    delay(1000);
  }
}

-Fletcher
9  Using Arduino / Programming Questions / Re: Writing output values to pins back to back seems buggy, digitalwritefast() too on: August 01, 2012, 03:10:58 am
Hi allanonmage

I don't need a video - just explane in simple words what you want to achive with your program.

I have looked at your program and this is how I interpretate it:

1) Waite for ServoDecode to give READY_state.
2) If READY_state: Set relays to running state.
3) If !READY_state: Set realys to not running state, and prepare for a new run.
4) If running state has been activitated for too long: Set relays to not running state and do nothing forever.

Is this correct?

-Fletcher
10  Using Arduino / Programming Questions / Re: Need help please ... small programming issue for a new user :( on: July 31, 2012, 03:21:00 am
Of corse it will  smiley-cry

A small "," is needed between the to variables.

-Fletcher

Mental note: Never trust anyone to have compiled the code they post
11  Using Arduino / Programming Questions / Re: Need help please ... small programming issue for a new user :( on: July 31, 2012, 03:04:40 am
Hi Hani

Code:
int led1 state = 0;
This will give you 2 variables and not 1.

How about this code
Code:
void setup(){
  pinMode(13,OUTPUT);
  pinMode(2,OUTPUT);
  digitalWrite(13,HIGH);
}

void loop(){
  delay(500);
  digitalWrite(13,!digitalRead(13));
  digitalWrite(2,!digitalRead(2));
}
Compiled but not testet.

-Fletcher
12  Using Arduino / Programming Questions / Re: small problem with float on: May 28, 2012, 02:52:46 pm
Hi louish

I think you are doing it wrong - you should keep the high resolution numbers as long as possible.

Recalculate the distance even if the responce from the gps is noisy and then you should decide if the new distance has changed enough -or you could make a running average.

-Fletcher
13  Using Arduino / Programming Questions / Re: Serial.println to external device drops characters on: May 15, 2012, 01:40:18 pm
Hi Kaj

Final glide, total energy compensated vario and driving an analog vario - you got a cool project there  smiley-cool Please remember to document it all and write a nice presentation  smiley I guess a lot of people could be interested in "upgrading" old instruments to better performance.

Last week I tried a Duo Discus with a LX9000. It was really nice to see which part of the circle I was gaining and loosing.

I'm not sure it's worth to recalculation the load factor and change in polar based on a G sensor. It's a rather short time that you pull the high G ... exept for the wind launch of corse.

Good luck getting the two devices to talk to each other.

-Fletcher
14  Using Arduino / Programming Questions / Re: Serial.println to external device drops characters on: May 15, 2012, 09:39:29 am
Hi Kai

I think you should try to figure out why the Vertica V1 is not receaving correctly.

Why do you want to take the total energi ballanced vario signal into XCSoar - does it has a better audio responce compared to the system you allready (LX ?000 or what ever) you have in the plane?

How do you obtain the dynamic pressure digitally? Is total energy ballanced vario done in arduino?


For those not familiar with gliding:
The vario is an instrument that tells if the plane is going up or down. It helps alot when you want to fly in the thermal upwinds. The instrument is often a flask where an instrument is meshuring if the air is going in or out - and at what rate. The instrument often has an audio output - with high pitch bib-bib-bib when you go up and low pitch buuup buuuuuuuuppppppp when going down (look out of the windshield - there are other gliders out there ... says the instructor!). A system like this has a build in error. If you fly fast and pull up (decreasing speed) you will gain altitude and therfore the vario indicates upwind. This is fals - the total energi of the plane has not gone up - you have only exchanged speed into altitude. To compensate for this the vario is connected to the tupe with dynamic pressure going to the speedometer. The vario signal is compensated with change in speed and up/down is only indicated if the total energy of the plane is changed.

-Fletcher

15  Using Arduino / Project Guidance / Re: drawing shapes on lcd panel using hand movement on: May 14, 2012, 04:40:15 pm
Have you tried using a permanent marker attached to your hand?

-Fletcher
Pages: [1] 2 3 ... 10