Show Posts
Pages: [1] 2 3 ... 7
1  Using Arduino / Programming Questions / Re: Significant difference between millis() and micros() on: July 23, 2014, 04:24:17 am
MarkT
Yes, I know you are right but I just don't get it.

And I don't like it when I don't understand it.
I know there would be some variance, however around 6mS seems to me to at the very extreme end of the scale.

All I'm doing is:

Capture timer
   do some work - show some variables on the display
recapture timer
then calculate the timer difference and show timer variance  on next round trip in loop()

I presume that both milliS() and microS() just captures the hardware timer and they don't interfere with each other ?
Maybe the tft display functions do something somewhere that causes this.

Board is a Mega running at 16mHz

Thanks for commenting


2  Using Arduino / Programming Questions / Re: Significant difference between millis() and micros() on: July 22, 2014, 06:32:51 am
Converted the output to a string as the printNumI in "myGLCD.printNumI(timelapseMillis,80,55)" takes an Int (16 bit) and Long is 32bit
However I still get up to 10mS variance in the output beetween the two values.

Hmm
3  Using Arduino / Programming Questions / Re: Significant difference between millis() and micros() on: July 22, 2014, 05:52:31 am
Okay, I have been doing some more tests and condensed the code a bit.
In the following code when I run it as it is BOTH millis() and micros() are showing the about same result, 43ms and 42,569uS.

However if I comment out this part, I get a result of 0mS and 42,499uS
Code:
//timelapseMillis = endtimeMillis - starttimeMillis;
timelapseMicros = endtimeMicros - starttimeMicros;


However if I comment out this part, I get a result of 34mS and 0uS
Code:
timelapseMillis = endtimeMillis - starttimeMillis;
//timelapseMicros = endtimeMicros - starttimeMicros;


This diffrence got me beat at the moment


Code:
#include <UTFT.h>

//Global Variables
volatile unsigned long  starttimeMillis = 0;
volatile unsigned long  endtimeMillis = 0;

volatile unsigned long  endtimeMicros= 0;
volatile unsigned long  starttimeMicros=0;

unsigned long  timelapseMillis = 0;
unsigned long  timelapseMicros = 0;


extern uint8_t SmallFont[];
UTFT myGLCD(ITDB32S,38,39,40,41);  // RS,WR,CS,RST


void setup()
{
  myGLCD.InitLCD();
  myGLCD.setFont(SmallFont);
  //DrawBaseScreen();
  myGLCD.clrScr();
  myGLCD.setColor(255, 0, 0);
  myGLCD.fillRect(0, 0, 319, 13);
  myGLCD.setColor(64, 64, 64);
  myGLCD.fillRect(0, 226, 319, 239);
  myGLCD.setColor(255, 255, 255);
  myGLCD.setBackColor(255, 0, 0);
  myGLCD.print("* Universal Color TFT Display Library *", CENTER, 1);
  myGLCD.setBackColor(64, 64, 64);
  myGLCD.setColor(255,255,0);
  myGLCD.print("* Version 7 *", CENTER, 227);
  myGLCD.setColor(0, 0, 255);
  myGLCD.drawRect(0, 14, 319, 225);
  myGLCD.fillRect(0, 14, 319, 225);
  // Draw crosshairs
  myGLCD.setColor(0, 255, 255);
  myGLCD.setBackColor(0, 0, 0);
  myGLCD.drawLine(159, 15, 159, 224);
  myGLCD.drawLine(1, 119, 318, 119);
  for (int i=9; i<310; i+=10)
    myGLCD.drawLine(i, 117, i, 121);
  for (int i=19; i<220; i+=10)
    myGLCD.drawLine(157, i, 161, i); 
}


void loop()
{
  starttimeMillis = millis();
  starttimeMicros = micros();

      DrawScreen1();

  endtimeMillis = millis();
  endtimeMicros = micros();

  timelapseMillis = endtimeMillis - starttimeMillis;
  timelapseMicros = endtimeMicros - starttimeMicros;

  //need a bit time to see the result
  delay(1000);





void DrawScreen1(void)
{
  myGLCD.setColor(255,255,0);
  myGLCD.print("Time mS", 5, 55);
  myGLCD.print("Time uS", 5, 75);
  myGLCD.printNumI(timelapseMillis,80,55);
  myGLCD.printNumI(timelapseMicros,80,75);
}






4  Using Arduino / Programming Questions / Re: Significant difference between millis() and micros() on: July 20, 2014, 01:44:09 am
Okay, I have been through all the source code in the utft files from
http://www.henningkarlsen.com/electronics/library.php?id=51

and apart from the init code I can't see any delays anywhere, but then again I'm not fluent in C/C++.
All the loops seem okay with no obvious wasted time cycles.

Kim
5  Using Arduino / Programming Questions / Re: Significant difference between millis() and micros() on: July 18, 2014, 07:13:55 pm
Here is all the code
A bit messy as I have playing around a bit with TFT screen stuff.

BTW, with all the code in the complete loop time is about 1/2 second, ie drawing the sine, cosine and tangent on the screen.



Code:
// UTFT_Demo_320x240 (C)2014 Henning Karlsen
// web: http://www.henningkarlsen.com/electronics
//
// This program is a demo of how to use most of the functions
// of the library with a supported display modules.
//
// This demo was made for modules with a screen resolution
// of 320x240 pixels.
//
// This program requires the UTFT library.
//

#include <UTFT.h>
//#include <UTouch.h>


// 16 bit interface pin numbers
//ITDB02   ( D0, D1, D2, D3, D4, D5, D6, D7, D8, D9, D10, D11, D12, D13, D14, D15, RS,  WR, CS, RST)
//ITDB02 lcd(37, 36, 35, 34, 33, 32, 31, 30, 22, 23, 24,  25,  26,  27,  28,  29,  38,  39, 40, 41);

//Heart Beat LED
int led = 13; 
int ledState = 0;


//Global Variables
unsigned long  gettime_Millis = 0;
unsigned long  newtimeMillis = 0;
unsigned long  timelapseMillis = 0;
unsigned long  numbertoshow = 0;


// Declare which fonts we will be using
extern uint8_t SmallFont[];
//extern uint8_t BigFont[];

// Set the pins to the correct ones for your development shield
// ------------------------------------------------------------
// Arduino Uno / 2009:
// -------------------
// Standard Arduino Uno/2009 shield            : <display model>,A5,A4,A3,A2
// DisplayModule Arduino Uno TFT shield        : <display model>,A5,A4,A3,A2
//
// Arduino Mega:
// -------------------
// Standard Arduino Mega/Due shield            : <display model>,38,39,40,41
// CTE TFT LCD/SD Shield for Arduino Mega      : <display model>,38,39,40,41
//
// Remember to change the model parameter to suit your display module!
UTFT myGLCD(ITDB32S,38,39,40,41);  // RS,WR,CS,RST



// Initialize touchscreen
// ----------------------
// Set the pins to the correct ones for your development board
// -----------------------------------------------------------
// Standard Arduino Uno/2009 Shield            : 15,10,14, 9, 8
// Standard Arduino Mega/Due shield            :  6, 5, 4, 3, 2
// CTE TFT LCD/SD Shield for Arduino Due       :  6, 5, 4, 3, 2
// Teensy 3.x TFT Test Board                   : 26,31,27,28,29
// ElecHouse TFT LCD/SD Shield for Arduino Due : 25,26,27,29,30
//

/*
UTouch  myTouch(  6,       //Pin for Touch Clock (D_CLK)
5,       //Pin for Touch Chip Select (D_CS)
4,       //Pin for Touch Data input (D_DIN)
3,       //Pin for Touch Data output (D_OUT)
2);      //Pin for Touch IRQ (DPenirq)

*/


void setup()
{
pinMode(led, OUTPUT);
//myTouch.InitTouch();
//myTouch.setPrecision(PREC_MEDIUM);

SetupLCD();
DrawBaseScreen();
        DrawScreen();

}

//000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
//000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
//000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
void loop()
{
//start timer
gettime_Millis = millis();//micros();


DrawScreen1();
HeartBeat();    //speed test.Frequency should tell how fast we do a round trip


//Calculate time taken to a loop
newtimeMillis = millis();//micros();
timelapseMillis = newtimeMillis-gettime_Millis;

//need a bit time to see the result
delay(1000);


//000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
//000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
//000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000



//-------------------------------------------------------
void  HeartBeat(void)
{
ledState = !ledState;
digitalWrite(led, ledState);
}






//-------------------------------------------------------------------------
void DrawBaseScreen(void)
{
// Clear the screen and draw the frame
myGLCD.clrScr();

myGLCD.setColor(255, 0, 0);
myGLCD.fillRect(0, 0, 319, 13);
myGLCD.setColor(64, 64, 64);
myGLCD.fillRect(0, 226, 319, 239);
myGLCD.setColor(255, 255, 255);
myGLCD.setBackColor(255, 0, 0);
myGLCD.print("* Universal Color TFT Display Library *", CENTER, 1);
myGLCD.setBackColor(64, 64, 64);
myGLCD.setColor(255,255,0);
myGLCD.print("* V5 *", CENTER, 227);

DrawMinorBackground();
DrawCrossHair();




//----------------------------------------------------------------
void DrawMinorBackground(void)
{
myGLCD.setColor(0, 0, 255);
myGLCD.drawRect(0, 14, 319, 225);
myGLCD.fillRect(0, 14, 319, 225);
}

//----------------------------------------------------------------
void   DrawCrossHair(void)
{
// Draw crosshairs
myGLCD.setColor(0, 255, 255);
myGLCD.setBackColor(0, 0, 0);
myGLCD.drawLine(159, 15, 159, 224);
myGLCD.drawLine(1, 119, 318, 119);
for (int i=9; i<310; i+=10)
myGLCD.drawLine(i, 117, i, 121);
for (int i=19; i<220; i+=10)
myGLCD.drawLine(157, i, 161, i);
}

//--------------------------------------------------------------
void    DrawScreen(void)
{
//DrawMinorBackground();
//DrawCrossHair();

myGLCD.setBackColor(VGA_BLUE); // Set the background color to blue behind the text following below


/*
// Draw sin-, cos- and tan-lines 
myGLCD.setColor(0,255,255);
myGLCD.print("Sin", 5, 15);
/*for (int i=1; i<318; i++)
{
myGLCD.drawPixel(i,119+(sin(((i*1.13)*3.14)/180)*95));
// delay(3);
}
       

myGLCD.setColor(255,0,0);
myGLCD.print("Cos", 5, 27);
/*for (int i=1; i<318; i++)
{
myGLCD.drawPixel(i,119+(cos(((i*1.13)*3.14)/180)*95));
// delay(3);
}
       

myGLCD.setColor(255,255,0);
myGLCD.print("Tan", 5, 39);
/*r (int i=1; i<318; i++)
{
myGLCD.drawPixel(i,119+(tan(((i*1.13)*3.14)/180)));
// delay(3);
}
        */

myGLCD.setColor(255,255,0);
myGLCD.print("Time mS", 5, 55);
numbertoshow = timelapseMillis;
myGLCD.printNumI(numbertoshow,80,55);


}

void DrawScreen1 (void)
{
numbertoshow = timelapseMillis;
myGLCD.printNumI(numbertoshow,80,55);
}





//---------------------------------------
void  SetupLCD(void)
{
// Sets up the LCD
myGLCD.InitLCD();
myGLCD.setFont(SmallFont);
}



6  Using Arduino / Programming Questions / Re: Significant difference between millis() and micros() on: July 18, 2014, 05:47:48 pm
unsigned long are used for the variables.

Okay, will try timing in a loop and see.
7  Using Arduino / Programming Questions / Significant difference between millis() and micros() on: July 18, 2014, 05:17:14 pm
When I run the code below and I change between millis() and micros() there is a quite a variance
With millis() the time shown varies between 2 and 3 milliseconds.

However if I change to micros(), the time shown is about 8700 micro seconds or 8.7 milli seconds.

Can anyone explain why the big difference ?

Code:
void loop()
{
//start timer
gettime_Millis = millis();    //micros();

DrawScreen1();     //draw on tft screen

//Calculate time taken to a loop
newtimeMillis = millis();    //micros();
timelapseMillis = newtimeMillis-gettime_Millis;

//need a bit of time to see the result
delay(1000);

8  Using Arduino / Project Guidance / Re: Need guidance: Measuring encoder position and sending data with Ethernet/WiFi on: December 09, 2013, 04:34:17 am
If the arduino can't keep up with the encoder count, you can use a dedicated chip (or the count function on the 32Bit Due) or use and FPGA like Pappilio which can run Arduino as well. As this is done in Parallel there should be no real issues there.
As for encoders, Absolute encoders gets expensive and all they really do is have a battery onboard that allows the count to be saved when the power goes off.
Just need to a home position for the encoder on power-up, thats all.

K
9  Using Arduino / Networking, Protocols, and Devices / Re: Auto Address Sensing on: November 28, 2013, 01:54:44 pm
I read that I2C is good for 20 to 30m with an I2C bus extender.

I read a bit about DMX, but don't see how this could be satify.

I would like the addresses to be set automatically, if feasible.
This way I can simply swap the slaves around and room_1 will always be room_1 no matter what slave I connect and without doing any addresssing apart from a power down/up.

The above may require that I run a another wire between each slave and each slave is initialiased in a set order, ie
when slave_1 is up and running and master has given it an address, the an output goes high to the Slave_2 which then get initilaised.

Feasible ?, I guess, but too complicated ?

K
                 
10  Using Arduino / Networking, Protocols, and Devices / Re: Auto Address Sensing on: November 27, 2013, 11:30:30 pm
Ha

Just stumpled across something about the I2C bus with a bus extender, it should be good for 20 to 30 meters.
Will investigate this......

K
11  Using Arduino / Networking, Protocols, and Devices / Auto Address Sensing on: November 27, 2013, 11:00:36 pm
Hi

I've got 8 slaves running from a master and would like to be able to have some sort of auto sensing.
Comminication is via RS485 and the slaves are approx 5 meters apart.

The slaves all does the same function and I/O's are the same.
So instead of manually set an address, I would like to be able to just plug the boards in and the master knows where the slave is.

So I figure that master talks to slave1 and slave1 talks to slave2 etc

I have looked around on the site for sample code but have't found any.
possible using the wrong seach terms, but I have tried a few name variations

Any suggestions ?

Kim
12  Development / Other Software Development / Re: eFLL (Embedded Fuzzy Logic Library) - Fuzzy Logic on Arduino on: September 22, 2013, 06:09:48 pm
Just stumbled across this.
Is anyone using this library and if yes, any comment ?

Thanks
13  Development / Other Hardware Development / Re: BLDC shield development suitable for Arduino due on: September 21, 2013, 05:00:51 am
I think that advanced position control, accel/decel rate, s curve smoothing with quadrature encoder feedback would be very useful.
Not sure if serial would be beneficial as could be done via the Arduino.

Nice work :-)
14  Using Arduino / Programming Questions / Re: dfrobot flame sensor coding on: August 29, 2013, 09:45:12 pm
Well, when using just one sensor the ambient light will have an effect.
One way is to add another sensor which is physically offset, ie 30 degrees, so you measure the difference and act when the difference is more than x
Off course you could also do this with one sensor, read the ambient light at the start, then act when it is more than x, just not as likely to be as reliable in real lift, but cheaper :-)

K
15  Using Arduino / Programming Questions / Re: clock-driven round robin scheduler on: June 02, 2013, 03:25:57 am
I just want to make sure that no tasks take longer than a set time and that I get back to some tasks within a specified time.

If the task overrun in time, I just need to set a semaphore so I know. Possible do some controlled shutdown or something.

Would be handy to know which task overflows, but at this point is properly not necessary.

I don't need priority, dynamic scheduling or anything like that.

Round Robin schedulers are predictable.
Trying to eliminate use of interrupts to get predictability

Was sure this most have been done numerous times, but maybe not released as free/w

Have been watching the TTE systems videos on youtube and like his approach, predictability :-)



Pages: [1] 2 3 ... 7