Show Posts
Pages: 1 2 3 [4] 5 6 ... 17
46  Forum 2005-2010 (read only) / Syntax & Programs / Re: Pin 13 blinks, and void loop doesnt loop on: July 08, 2010, 08:27:46 am
Not sure if this is the problem, but at first glance you've mistaken the assignment (=) operator with the compare (==) operator a number of times.
47  Forum 2005-2010 (read only) / Syntax & Programs / Re: ADCH and ADCL - buffered? on: June 29, 2010, 01:55:34 pm
I interpret the excerpt to mean that ADCL and ADCH are updated only when the conversion finishes, and only if the result isn't in the middle of being read (ADCL read but ADCH not yet read).

Figure 26-7 of the same datasheet gives a further clue.  The ADC timing diagram for free running conversions.  The ADC result is shown to persist through the start of the next conversion.
48  Forum 2005-2010 (read only) / Syntax & Programs / Re: ADCH and ADCL - buffered? on: June 29, 2010, 12:26:26 pm
This should help.  From s26.3 from the atmega 1280 datasheet...

"If the result is left adjusted and no more than 8-bit precision is required, it is sufficient to read
ADCH. Otherwise, ADCL must be read first, then ADCH, to ensure that the content of the Data
Registers belongs to the same conversion. Once ADCL is read, ADC access to Data Registers
is blocked. This means that if ADCL has been read, and a conversion completes before ADCH is
read, neither register is updated and the result from the conversion is lost. When ADCH is read,
ADC access to the ADCH and ADCL Registers is re-enabled."
49  Forum 2005-2010 (read only) / Syntax & Programs / Re: Best method for timing? on: June 15, 2010, 12:30:11 pm
The former also relies on division (slow).  The 2nd option should be faster.
50  Forum 2005-2010 (read only) / Syntax & Programs / Re: Unable to create .h for .cpp file on: June 11, 2010, 01:27:51 pm
I can confirm this bug in 0017 for Windows.  I've grown accustomed to creating the .h and .cpp files outside the UI first and then starting the interface.
51  Forum 2005-2010 (read only) / Syntax & Programs / Re: Syncing Timer1 and Timer2 on: May 05, 2010, 02:36:45 pm
Tutorials?... no.  But the atmega datasheets are excellent reference.
But I suspect you might not need to go that deep once we understand your application.  We'll see once you get back to work at your evening job smiley-wink
52  Forum 2005-2010 (read only) / Syntax & Programs / Re: Syncing Timer1 and Timer2 on: May 05, 2010, 01:27:23 pm
None of the timers really count in microseconds or milliseconds.  All the timers count in time with the system clock with a divisor.
Another key difference is Timer0 and Timer2 are 8-bit counters.  They roll-over at 255.  Timer1 is a 16-bit Timer... it rolls-over at 65535.

Inherent to your question is seemingly a misunderstanding of Timers on the Arduino.  Can I encourage you to post your problem in a little more detail?  There is probably another approach to arrive at a solution.
53  Forum 2005-2010 (read only) / Syntax & Programs / Re: Big Question on: April 14, 2010, 03:39:40 pm
Nope... not too clear.  Best I can surmise is you're building a time machine.  In which case why don't you travel back in time to today and tell yourself how you did it?
54  Forum 2005-2010 (read only) / Syntax & Programs / Re: Trouble with extending a class on: April 12, 2010, 09:29:52 am
Well, some research suggests the OP is experiencing expected behaviour...

http://www.newlc.com/en/Operator-Function-Overloading-and.html

It's apparently referred to as "name-hiding".  See the example at the bottom of the page at above link.
55  Forum 2005-2010 (read only) / Syntax & Programs / Re: Trouble with extending a class on: April 12, 2010, 09:21:07 am
but (I would suggest) returnVal(char*) isn't redeclared.  returnVal(float) is declared in addition.
I'm with jr: I would have expected the extended class to simply provide one overload for returnVal in addition to the existing declaration in the base class.
56  Forum 2005-2010 (read only) / Syntax & Programs / Re: Serial.read and so on on: April 01, 2010, 11:10:09 am
Alternately, if you intend to send the binary-encoded values of -1023 -> 1023 (instead of the string representations) you'll need to do some highhbyte/lowbyte calls to split it up, send it over serial in 2 separate bytes, then reassemble it at the receiving end (bitshift the first byte by 8 places and OR it with the second byte).

If you need more specifics I (and others) can help but this might be a good enough start.
Or Paul's code will probably do the trick if you're justing sticking to string representation...
57  Forum 2005-2010 (read only) / Syntax & Programs / Re: Help with measuring clock cycles on: March 26, 2010, 12:03:02 pm
You can store the value of TCNTn at the point in time you are interested in.  Then later compare the TCNT value to the stored value.


Code:
unsigned int myTimeDelta;
...
myTimeDelta = TCNT1;
stuff();
myTimeDelta = TCNT1 - myTimeDelta;
Serial.print(myTimeDelta, DEC);

This will give you the number of TCNT1 clock ticks that elapsed while "stuff()" executed.  I believe TCNT1 runs at prescaler = 1 by default but you can confirm by checking the value in TCCR1B.
58  Forum 2005-2010 (read only) / Syntax & Programs / Re: timer control register question on: March 25, 2010, 01:48:40 pm
It's not the exact same code...
0x10101010 != 0b10101010
59  Forum 2005-2010 (read only) / Syntax & Programs / Re: Help Needed.  Serial data manipulation. on: February 24, 2010, 08:24:52 pm
Sounds like you're already talking yourself through the necessary logic.  The details depend on your specific application.  Are you concerned about dropping/discarding data?  What are the possible errors you'll encounter?

You need to consider the logic rules the input will follow and write the handler accordingly.  If the input doesn't match the expected, then reset the state and wait for a delimiter to resume processing.

Right now you've described this unique pattern that defines the start of a new data packet:  carriage-return, single digit, carriage-return
60  Forum 2005-2010 (read only) / Syntax & Programs / Re: Help Needed.  Serial data manipulation. on: February 22, 2010, 06:20:01 pm
Nope, no laughing at noobs that learn.  Only laughing at noobs that don't.

You just need some experience to start thinking a little more like a computer.  It looks like you expect Serial.read to read 3 numbers when you assign it to incoming3byte.  But serial.read only ever reads 1 byte at a time.

You also might need some info on the difference between a byte value and the ASCII representation.  Numbers 0-9 as ASCII characters have decimal values of 48-57.  See http://www.asciitable.com/
Note decimal 13: carriage return.  There is an invisible byte (maybe two) sent between the first 3 digits and the 4 digit that indicates the new line and/or carriage return.

The last point I'll make is that just because Serial.available() is true, it doesn't mean that Serial.Has3DigitNumber_andalso_1digitNumber is true.  Depending on how fast the data coming in is injected onto the serial port the Arduino might try and read it before it arrives.

Here's some half-baked code off the top of my head of what I think you're trying to do.  I'll leave it to you to try and fix my mistakes and get it to compile (and fix the bugs)...

Code:
byte AllFourDigits[4];
byte index = 0;

void loop()
{
  if (Serial.available()) {
    byte b = Serial.read();
    if (b != 13 && b != 10)  // swallow newline/carriage return characters
    {
      AllFourDigits[index] = b;
      index++;
    }
  }

  if (index == 4)
  {
    Serial.print("%");
    Serial.print(AllFourDigits[0]);
    Serial.print(AllFourDigits[1]);
    Serial.print(AllFourDigits[2]);
    Serial.print("/");
    Serial.println(AllFourDigits[3]);
    index = 0;
  }
}
Pages: 1 2 3 [4] 5 6 ... 17