Show Posts
Pages: [1] 2 3 ... 9
1  Development / Other Software Development / Re: RunningAverage Class on playground (updated) on: May 07, 2014, 01:01:29 pm
Code:
GaussianAverage avg1(NUM_AVGS);
GaussianAverage avg2(NUM_AVGS);
GaussianAverage avg3(NUM_AVGS);
GaussianAverage avg4(NUM_AVGS);

//In code to add values to the moving average
avg1 += 10;
avg2 += xx...;

// Then process and get the result
float reault1 = avg1.process().mean;

Library: http://github.com/ivanseidel/Gaussian
2  Using Arduino / Project Guidance / Re: Sanity check on some timing code on: April 07, 2014, 04:42:34 pm
If I'm not mistaken, interruption will NOT occur anymore. What it means is: it will be skipped.

You're mistaken.

Using interrupts introduces various issues that can trip up the unwary, and my advice is to not use them unless absolutely essential, and then only reluctantly and to the minimum extent possible. However, when you're using interrupts correctly there are times when you need to disable interrupts. Doing this will cause interrupt handling to be delayed but (when done correctly) does not mean that interrupts would be 'skipped' entirely.

I don't think so. Interruptions are the most effective way of doing things on the microcontroller. For both precision on timing or even low-power consumption. They are made to be used, not to be left asside...

If I'm not wrong (I would need to test, but I can't be sure). If you set no-interrupts, and let's say... 5 interruptions occurs in the mean time. Those wont happen, even after interrupts is called.

ARM Cortex has a very complex structure, that allows many ways to deal with interruptions. One of them, is to dispose interruptions, other, is to run after one is complete. Other, is to run imediatly if priority of the new one is higher...

But that would lead us to a deep talking about the microprocessor datasheet... Something I avoid looking at, but it's essential some time...

My advice is: Use Interruptions (Timers, border...), and be aware of all it's requirements, to not create problems yourself... As I said, it's really easy to fix some small issues, but you just must be aware of them to develop a more robust code.

There are times, you will need to use noInterrupts, but that's only a few, when, perhaps, you are communicating with some peripheral, or doing a highly time sensitive action...

Well, try it yourself... I really like timing of things, and I spent a big part of my developments looking and testing it. Maybe it explain why I bough an FPGA  smiley
3  Using Arduino / Project Guidance / Re: Sanity check on some timing code on: April 07, 2014, 10:29:37 am

If a microprocessor is powered up it is executing code and using energy. It makes no difference whether it is executing useful code or just chasing its tail.


That's it =)

About your code. Avoid using no-interrupts and interrupts. Always remember that you must have two goals:
+ Execute things fast (as Robin Said too)
+ Do not skip interruptions/delay it

The second one occurs when you put a 'nointerrupt'. If I'm not mistaken, interruption will NOT occur anymore. What it means is: it will be skipped.

Try to do your calculation as much indepedent from it's Timer function. (simple example, but you get the idea):

Code:
int x = 10;

void loop(){
  x = x*2;
  // <--- If interruption get called here. x will be twice it's value.
  x = x+2;
  delay(100);
}

You can fix it easily with helper variables:

Code:
int x = 10;
void loop(){
  int helperX = x;
  helperX = helperX * 2;
  helperX = helperX + 2;
  x = helperX;
 // In no situation, x will be in the middle of its 'calculations';
}

And that's correct... Arduino do not support Real threads, but you can take advantage of such library to help you with code organization. It would even be possible to use no timers at all, with a great control over what's is going on... But, keep with Timers. They are more precise for your case.

Ivan
4  Using Arduino / Project Guidance / Re: Sanity check on some timing code on: April 07, 2014, 10:25:14 am

If a microprocessor is powered up it is executing code and using energy. It makes no difference whether it is executing useful code or just chasing its tail.


That's it =)

About your code. Avoid using no-interrupts and interrupts. Always remember that you must have two goals:
+ Execute things fast (as Robin Said too)
+ Do not skip interruptions/delay it

The second one occurs when you put a 'nointerrupt'. If I'm not mistaken, interruption will NOT occur anymore. What it means is: it will be skipped.

Try to do your calculation as much indepedent from it's Timer function. Example:

int x;

void loop(){
  x = x*2;

  x = x/2;
}
5  Using Arduino / Project Guidance / Re: Sanity check on some timing code on: April 03, 2014, 07:03:58 am
Hi,

You can use multiple timers at the same time without problems, but if one interruption occurst on the middle of another, it will wait (default behavior).

What you can use to simplify even more, is to use my other Library ArduinoThread (https://github.com/ivanseidel/ArduinoThread)

After reading it's main page, should give you an idea on how to implement it...

Also, notice that: Doing no calculations, and, running a empty loop consumes the same power on the uC. So, if you are not doing it because of that... it won't be a problem.

Ivan
6  Products / Arduino Due / Re: Servo library + timer library? on: March 25, 2014, 10:07:00 pm
ivanseidel,
I tested it and it works for my project.
Many thanks and keep on the good work!

Thanks! Nice that it worked and helped...

Ivan
7  Products / Arduino Due / Re: Timer Interrupts on Due on: March 25, 2014, 07:44:12 am
Hello,

Because there are some people with this problem, I made a modification on DueTimer that will allow you to put to work both Servo and DueTimer together.

I didn't have time to test, but I'm pretty sure everything will work just fine.

Here is the documentation on how to make it work: https://github.com/ivanseidel/DueTimer#compatibility-with-servoh
8  Products / Arduino Due / Re: Servo library + timer library? on: March 25, 2014, 07:28:03 am
Hello,

Because there are some people with this problem, I made a modification on DueTimer that will allow you to put to work both Servo and DueTimer together.

I didn't have time to test, but I'm pretty sure everything will work just fine.

Here is the documentation on how to make it work: https://github.com/ivanseidel/DueTimer#compatibility-with-servoh
9  Products / Arduino Due / Re: timer interrupts on: March 24, 2014, 10:45:04 pm
Hi, a GitHub user started some work on a fork of my DueTimer library: https://github.com/pklaus/DueTimer/tree/counter-implementation

I don't know if he completed it.

I'm currently working on a newer version of DueTimer, that will cal 'ArduinoTimer', and I (hope) to accomplish a Generic Timer class, that can work across multiple platforms. However, Arduino is going trough some changes on the Library patterns. I was waiting it to complete to start working on it.

The Idea is to have PWM, Counters (Virtuals and Physical), Timers and so on, all working with major Arduino Platforms.

Ivan
10  Development / Other Software Development / Concept Library for Sensors and IO on: March 11, 2014, 01:10:26 pm
It might worth a look at the (under documentation) library I have schematized and made.

It's called ArduinoSensors, and is made to serve as a pattern for future developers, and also to simplify the usage of classes and  let code even more robust with Thread concepts.

I have implemented lots of sensors already that I used. I have also extended it and implemented my own classes for very specific purpose.

The repository can be found here: https://github.com/ivanseidel/ArduinoSensors

Some cool classes that are included, are `DigitalOut`, `DigitalIn`, `AnalogIn` and `AnalogVoltage`.

To show how they work (for example):
Code:
DigitalIn myButton(9);

// Check if Pin is HIGH
if (myButton)...

// Check if Pin is LOW
if (myButton == LOW)...
// Reads it's value
boolean val = myButton.readValue();

DigitalOut myLed(13);

// Turns LED on
myLed = HIGH;
myLed.turn(HIGH);
myLed.turnOn();

// Turns LED off
myLed = LOW;
myLed.turn(LOW);
myLed.turnOff();

Or something complex, using Async sensor fetch in a Thread controller:
Code:
// Create a new ThreadController that will run always
// (means it will check if it's threads should be runned everytime)
ThreadController threads(0);

// Create some sensors
DistanceInterface *myDist1 = new SharpLong(A0);
DistanceInterface *myDist2 = new SharpShort(A1);
TemperatureInterface *thermometer = new MLX90614(0x32);
AngleInterface *myCompass = new HMC6352();

// Each sensor has it's interval set to minimum possible
// or something good to work with (20ms - 70ms).

// But they ARE Thread objects, so you can make use of
// it's methods:

// Compass should be read every 60ms
myCompass.setInterval(60);

// Add to the thread controller
threads.add(&myDist1);
threads.add(&myDist2);
threads.add(&thermometer);
threads.add(&myCompass);

// Now, just call threads.run(); to automatically run what is needed
// (perhaps in a Timer Callback? or in Loop.. whatever)
loop(){
  threads.run();

  // Get the most recend value WITHOUT reading the sensor
  double currentAngle = myCompass->getAngle();
  float distance = myDist1->getDistance();
  [...]
}

Anyway, you can use it the way you want. It is not 100% documented since it's a LOT of work to do, but I'm shure it can help others.
11  Development / Other Software Development / Re: [Published on GitHub] LinkedList Class (Fully implemented) on: February 24, 2014, 07:14:47 pm
I think that you should be allocating memory for the string everytime you create a new one, otherwise you will just be overriding it, and all values in the IP struct inside the LinkedList, will ref. the same pointer.

And also, alocating more than the arduino can, can cause it to crash  smiley-eek

If that doesn't work, I can try it here (without arduino right now...)
12  Development / Other Software Development / Re: [Published on GitHub] LinkedList Class (Fully implemented) on: February 05, 2014, 03:10:56 am
@ivanseidel, your remove function assumes that bool can be converted to any type of T.
Code:
if(index < 0 || index >= _size)
  return false;

Maybe return a default initialized value:
Code:
if(index < 0 || index >= _size)
  return T();

This now only assumes that T has a default constructor or is a POD.

The same scenario appears in other functions.

I think the problem is in fact, storing things larger than a simple pointer to a memory, number, boolean...

returning T(); would only work for object types that are NOT pointers, right?
13  Development / Other Software Development / Re: [Published on GitHub] LinkedList Class (Fully implemented) on: February 05, 2014, 03:07:01 am
Hi,
  Thanks for fast response.  Unfortunately that doesn't work either.  Same errors.   Computers have really been troublesome for me lately. lol.

Sorry for my (fast) but wrong response!

Now I had time to try it out, and seems that you are trying to 'include' the instance of the object, not the pointer to it. Here is how I would do, because then you are still able of passing the object without having to copy it or anything else...

Note that, the type of the LinkedList is not pointer, but the class inside it is. So, if you are adding elements to it, if they are instance objects (not pointers), don't forget the '&' before it...

Perhaps I could work out some examples for the library...

Code:
#include <LinkedList.h>

LinkedList<int> myLinkedList = LinkedList<int>();
 class test
{
public:
  test();
  int x;
};
test::test(){}

LinkedList<test*> myLinkedList2 = LinkedList<test*>();
void setup()
{
  myLinkedList = LinkedList<int>();
  myLinkedList2 = LinkedList<test*>();
}
void loop()
{
}
14  Development / Other Software Development / Re: [Published on GitHub] LinkedList Class (Fully implemented) on: February 04, 2014, 04:16:41 am
Hi!
Take a look at pointers and objects by instance to understand it better. But in your case you are trying to instantiate a poiinter linked list with an instance.object...

Also, when working with the list within different scope (loop, void, classes...), its a good practice to instantiate as a poiter. (If there will be lots of classes, its a good idea to delete it after you dont need it anymore).

What i use to do is:

Code:
LinkedList<mytype> *myList;

void setup{
  myList = new LinkedList<mytype>();
}

// In your code
myList->add(....);
15  Products / Arduino Due / Re: Lost Bytes when reading Serial1 when receiving also data via native USB port on: January 03, 2014, 09:36:43 pm
Ivanseidel, thank you for your comments, however I was already aware of that general issues with serial communication.
In my project, I use 32Bit CRC, so I detect transmission errors with very high probability.  Most errors are not reported as CRC check errors since the incorrect size of the received message is detected before that. With a baud rate of 115200, I detect erroneous reception about once per second, and this is due to the described Arduino bug only. This error rate is far above the physical transmission error rate and in no way acceptable.

Well done! 1 error per second is a lot of errors! It must be something wrong in the code/register dealing...

I cannot help you more than this... just with the hardware in my hands and a lemonade to start thinking, sorry =[
Pages: [1] 2 3 ... 9