Show Posts
Pages: [1] 2
1  Using Arduino / Programming Questions / Re: Is this a bug in rvalue promotion? on: November 24, 2013, 07:07:34 pm
hehe, well if we keep hiding them no one will fix them.
I think its a crime this compiles without warning right now by default:

int c;
if (c == 1)

i.e. doesn't even gripe about uninit'd vars.

Seems fairly easy to modify the IDE for -Wall if I have the IDE on linux/Mac, but not so easy on Windows  - any simple trick or do I have to change compiler.java myself and rebuild?  Think its time to use a proper IDE...
2  Using Arduino / Programming Questions / Re: Is this a bug in rvalue promotion? on: November 24, 2013, 06:49:16 pm
Thanks guys, I like to use -Wall in my (new) projects at work, from now on always gonna do it on Arduino projects.
We should make this the bloomin default, helps new peeps write better code too.
3  Using Arduino / Programming Questions / Re: Is this a bug in rvalue promotion? on: November 24, 2013, 11:43:00 am
Sure, I know that, but why no warning about loss of precision?
I've found two other sketches with this 'sleeping' bug now.
4  Using Arduino / Programming Questions / Re: Is this a bug in rvalue promotion? on: November 24, 2013, 11:40:24 am
Thanks for the reply guys, I know casting etc will fix it and I knew it was a 16-bit interference.  However, I don't think its obvious - there's some guys banding about code to handle millis() properly and using (sec x 1000) in the test, which I copied, and that is plain wrong without being explicit about the literal type.

I would've at least expected a compiler warning about loss of precision.

Been spending too much time on 32/64-bit OS's I suppose.
To illustrate this I've compiled essentially the same code on gcc on my Mac, it works fine.

#include <stdio.h>
int main (int argc, char **argv)
{
        unsigned long a = 0;
        unsigned long b = 0;
        a = a + 33000;
        b = b + (33 * 1000);
        printf ("a = %lu\n", a);
        printf ("b = %lu\n", b);
}

hriss-MacBook-Pro:~ chris$ gcc p.c
Chriss-MacBook-Pro:~ chris$ ./a.out
a = 33000
b = 33000

5  Using Arduino / Programming Questions / Is this a bug in rvalue promotion? on: November 24, 2013, 11:01:07 am
I know Arduino language isn't strictly C/C++, but many of us just use and expect a lot of C behavior to work in sketches.
I was just debugging a weird time related bug and came across an unobvious casting / promotion issue.  I'm sure others must have hit it but I'd appreciate some feedback as it feels like a compiler promotion bug to me.  Certainly for me, it's been responsible for several bugs in sketches where I've tended to use expressions like 'valueMs = (numSeconds * 1000)', especially when numSeconds > 32.

I am using IDE 1.5.4.

So, if you do this:

Code:
unsigned long a = 0;
a = a + 33000;

You get 33000.
No surprises.

Now do this (quite common if a is a time in millisecond):

Code:
a = a + (33 * 1000);

You will get 4294934760.
The brackets don't matter.

If you repeat the above with 32000 instead, it will be fine.

So it seems rvalues are not promoted to the largest type's resolution if you use an expression like that.  It looks like it is using 16bit signed short for the RHS.  Isn't this wrong?   At least in C/C++ world, where rvalues should get promoted to the largest size of the various operands, and since 'a' is a unsigned long and on the RHS, I would expect (33*1000) to get promoted to unsigned long.

You can work round it in various way,
e.g.
Code:
a = a + ((unsigned long)33*1000);
a = a + (33.0 * 1000);
etc.

i.e. force explicit upcasts but this is not obvious.

This triggered 'weird' bugs in code if you use expressions like this:

Code:
if ((unsigned long)(millis() - waitUntil) >= (60 * 1000) {

Example to repro the problem:

unsigned long a = 0;
unsigned long b = 0;
void loop() {
  Serial.print ("a = ");
  Serial.println (a,DEC);
  Serial.print ("b = ");
  Serial.println (b,DEC);
  a = a + 33000;
  b = b + (33*1000); // not ok
  delay (250);
}

My ouput (a and b should be the same but they are not):
a = 0
b = 0
a = 33000
b = 4294934760
a = 66000
b = 4294902224
a = 99000
b = 4294869688
a = 132000
b = 4294837152

Chris
6  Using Arduino / Networking, Protocols, and Devices / Re: PoE module current question on: November 16, 2012, 08:21:28 pm
I was worried this wasn't going to be simple.  I have multiple modules to power (including the MEGA);  RS232, RS422 and the killer, the SM5100B cellular board which can burst up to 1.5A.  I know powering via USB is out of the question and even via the DC socket is not going to work reliably due to that cellular board, so I was hoping I could power everything neatly from the PoE.

What would you suggest in this situation?  It seems ugly but I suspect I need a PSU going into a new DC jack on my project box to power that cellular board and Arduino separately, and just forget about PoE.

Cheers
7  Using Arduino / Networking, Protocols, and Devices / Re: PoE module current question on: November 16, 2012, 07:08:18 pm
Thanks John, so say thats 10W approx.  Does the PoE module makes this available via the 5V and GND pins on the headers?  I'm trying to figure if its safe to pull about 2A@5V from them to power various modules.  Is there any additional on-board limits or current protection going to restrict what the PoE is feeding?
8  Using Arduino / Networking, Protocols, and Devices / PoE module current question on: November 16, 2012, 03:08:40 pm
If I have an official Arduino Ethernet shield with PoE module and using a proper.3af 48V injector, in theory I can feed 15W in.  Question: is this 15W actually drawable via the Arduino +ve and GND supply rails?  If not, what's the point and where can I draw it?

I think I read the PoE module will convert from (36-) 48V down to 12V, but I'm also aware of current limitations on the Arduinos DC socket and wondering if the Arduino is going to limit the power from the PoE in any way.

(Motivation - I have quite a few external modules to power and talk to from the Mega and wondering if the PoE is up to the job).
9  Using Arduino / Installation & Troubleshooting / Intermittent MEGA lockups - SM5100b? on: November 16, 2012, 02:23:30 pm
hi,

I have a controller board based on a MEGA R3 which is locking up randomly after say 5 hours, then it will stay down for a few hours, then recover and work for a few hours, etc.  I have a number of these controllers I've made and the only difference in this one is it has a Sparkfun SM5100B board which is obviously under suspicion.  I am aware of the power issues of the SM5100B and have things powered by a separate 12V PSU.  However, I notice it (the top of the SM5100B board) gets quite hot and I'm not sure if this is a power or heat issue.

Can someone tell me if the Arduino has a thermal or over current 'fuse' which could cause this behavior? 

Note, my sketch is identical on all my controllers and I'm not even talking to the SM5100B board on this one, although it is powered up.

Cheers
Chris




10  Using Arduino / Networking, Protocols, and Devices / Arduino serial to 20ma current loop on: October 27, 2012, 11:36:07 am
Hi,

I need to interface to a serial interface on an industrial bus.  The interface has a 20ma current loop, logical 1 = 0mA in loop, logical 0 = 20ma.  It expects me to provide 6.5VDC.  It runs at 4800 baud.  To complicate things it has a parity bit, i.e. its 8o1.

( I know I can buy a dongle that will do say RS232 to 20ma current loop, but obviously I'd have to go RS232 first and checking my options. )

I presume I can connect one of the MEGA's hardware UARTs to it via appropriate circuitry and the parity can be handled with an serial register, e.g. UCSR1C=..

Regarding the circuit, will something like Midi circuit work?  I know they are current loop and I presume if I set things for the right current and voltage, I should be good to go.  I need RX an TX though.

Any advice from anyone whose already done this?

ta
chris
11  Products / Arduino Due / Re: UART question on: October 23, 2012, 09:04:17 am
Thanks guys, I couldn't see any mention in the datasheet either but I thought a newer chip like that probably had something.  Still, if I can use the extra RAM to hike up the serial buffers I will be happy.
12  Products / Arduino Due / UART question on: October 23, 2012, 07:09:46 am
Does anyone know if the UARTS in the Due have hardware buffers/fifos?  Or are they expecting the serial library to do the buffering and defaulting to 64-bytes again?

ta,
chris

[ I, like others, sometimes modify the serial library (especially on a MEGA project I have) to avoid serial overflows when the sketch has to do some length op like send an email.  This extra RAM on this baby would allow me to bump my UART buffers up to 1K or whatever it takes to minimise my serial data loss. ]
13  Using Arduino / Networking, Protocols, and Devices / Re: Is Ethershield actually live on: August 31, 2012, 05:29:39 am
When I had a need to do that (to verify just LAN connectivity, not internet), I did a connect to the default GW address port 80 that I used in the ethernet begin.  This is my broadband router's web page, most listen on port 80 on the lan and I read the first line just to make sure I got some kind of http reply. 
14  Using Arduino / Networking, Protocols, and Devices / Known bug in cosm example / ethernet lib? on: August 30, 2012, 07:55:00 pm
Before I embark on a debugging session, is there any known issue in the ethernet library or cosm example in 1.0.1 where it would do the following:

I have an Arduino that logs to Cosm (Pachube) every 10 sec and was logging for many days fine.  I noticed yesterday it stopped logging to Cosm.  I have a telnet-like daemon on the Arduino to allow me to telnet into it and issue some queries (e.g. it can report on errors that happened).  However, as soon as I telneted in I saw my Cosm http requests being echo'd back.  This is not expected, the Cosm code only writes to its own EthernetClient socket (lifted from the 1.0.1 example) yet it was writing down my telnet accepted socket.  Clearly, the Cosm code has ended up using the wrong socket and was failing with its own.  It smells like there's a problem in the Cosm example code as I see some other guys have reported problems with it - is this one of them?   I hate to think it might be an ethernet lib bug.

chris
15  Using Arduino / Networking, Protocols, and Devices / Re: UDP.stop() undocumented on: August 20, 2012, 12:37:36 pm
Just for others, if you use UDP.stop() it seems to work and I don't seem to need a delay after the endPacket() method before the stop().  Now I can create embryonic UDP instances and close them properly.

I think the UDP documentation and samples should be updated to mention UDP.stop().
Pages: [1] 2