Show Posts
Pages: 1 2 [3] 4
31  Using Arduino / Programming Questions / Re: Help with Java GUI. on: March 15, 2013, 07:55:53 am
Read Strings from your 'input' Reader and append( ... ) the String to your JTextArea. Take care that the document doesn't become too large.

kind regards,

Jos
32  Using Arduino / Programming Questions / Re: (char)n vs char(n) on: March 10, 2013, 10:03:07 am
'(char)n' is the old C notation; 'char(n)' is C++s functional cast notation; both do exactly the same thing.

kind regards,

Jos
33  International / Nederlands / Re: Communicatie tussen 2 arduino's (integer) on: February 28, 2013, 07:58:44 am
Die 'kabel' tussen de twee Arduinos, is dat 'n usb kabel? Zo ja, dan is 't eenvoudig: baud rate etc. gelijk zette en babbelen maar ...

vriendelijke groet,

Jos
34  International / Nederlands / Re: Communicatie com poort (Arduino) en java on: February 19, 2013, 09:49:15 am
Zelf gebruik ik al 'n tijd RXTX tesamen met de arduino driver (bjigeleverd bij de IDE); w.b. Java, is 't gewoon 'n USBx port openen, baudrate etc. instellen en babbelen maar ;-) Vanzelfsprekend moet de arduino de binnenkomende bytes begrijpen en de juiste commandos uitvoeren (bijv. sensorwaarden naar de Serial bus schrijven). Hier haal ik de RXTX spullen vandaan: http://guides.machinescience.org/mod/forum/discuss.php?d=263

vriendelijke groet,

Jos
35  Using Arduino / Programming Questions / Re: Trying to learn how to code Sketches on: February 19, 2013, 04:06:13 am
Quote
A sketch also has a main() function,
No, it doesn't.
The IDE adds the main to the sketch that you write.

That's what I wrote in my previous reply ;-)

kind regards,

Jos
36  Using Arduino / Programming Questions / Re: Trying to learn how to code Sketches on: February 19, 2013, 03:29:53 am
Quote
I don't know why they decided to use the term "sketch", because it's a C program.
No, because a C program would have a "main".

A sketch also has a main() function, it is written for us and calls the setup() function once and repeatedly it calls the loop() function. It's the IDE that juggles with our C/C++ files, feeds them to the linker (including that main() function) and voila.

kind regards,

Jos
37  Using Arduino / Programming Questions / Re: is a read/write from/to an uint8_t atomic? on: February 18, 2013, 07:55:57 am
I sincerely disagree with the 'religion' that enabling interrupts in an interrupt handler should be a bad thing, but I redesigned (and re-implemented) my handler: it is interrupt driven by changing (rising or falling) edges (it is a state machine again, same as it was before) and I'm going to try both approaches; my main program loop has nothing else to do while a remote key is pressed (there's one user only) so the processor can be 'away from the job' for 0.1s while it's reading the IR remote, but doing the reading entirely interrupt driven doesn't hurt. b.t.w. nice article; I bookmarked it.

kind regards,

Jos
38  Using Arduino / Programming Questions / Re: is a read/write from/to an uint8_t atomic? on: February 18, 2013, 03:51:33 am
You won't lose a millis() tick in 560uS - the interrupt is queued.

Thanks, I have to remember that; I don't think this queueing of interrupts has a buffer? If yet another interrupt happens, will it overrun the already pending interrupt or is it thrown away? As my decoding handler is now, it takes +- 100ms to complete and (so) +- 100 millis() interrupts have happened (and many micros()).

kind regards,

Jos
39  Using Arduino / Programming Questions / Re: is a read/write from/to an uint8_t atomic? on: February 18, 2013, 02:48:59 am
Let me turn the question around.

What is your objection to doing what the IRremote library does? It doesn't re-enable interrupts inside an ISR.

I've seen that library; it records 'ticks' between state transitions and it uses 100 two byte ints for it (200 bytes!) and it decodes afterwards. I decode 'on the fly' for one particular protocol (NEC); reading 32 bits in that protocol takes +- 108 millis and I don't want to lose the millis() ticks. The 'header' pulse takes 560us and I might lose a millis() tick in there. Maybe if I use edge change interrupts (my first approach) I don't need to (re)enable interrupts inside my handler ...

kind regards,

Jos
40  Using Arduino / Programming Questions / Re: is a read/write from/to an uint8_t atomic? on: February 18, 2013, 01:41:29 am
Fair enough, but enabling interrupts inside an ISR is a last resort, as far as I am concerned.

Why is everybody so itchy when it comes to (re)enabling interrupts in an interrupt handler? I'm not longjmp( ... )ing around, I just want the micros() and millis() things to keep working (I have to keep track of a wall clock time (*)). Neither does my interrupt handler need to be reentrant ...

kind regards,

Jos

(*) yes, the device syncs its notion of time with an NTP server each day.
41  Using Arduino / Programming Questions / Re: is a read/write from/to an uint8_t atomic? on: February 18, 2013, 01:36:49 am
You are enabling interrupts within an interrupt handler? That is a big red flag.

No it isn't, I know what I'm doing (<--- famous last words ;-) My interrupt function is triggered by a falling edge and then it starts decoding an IR signal from a digital pin; that can takes several milli seconds (I simply poll that pin in the interrupt function) and I want the millis() etc. interrupts to go on. At the start of my function I've detached it from the particular interrupt because I don't want it to be called recursively by another falling edge on that pin. b.t.w. I only enable interrupts after I've detached my function from that falling edge interrupt.

Instead of polling the IR receiver in the ISR, why don't you leave the interrupt attached, and at each interrupt:

- call micros() to get the current time
- calculate the time since the previous edge, so that you can decode the next bit
- store the time you got from micros(), ready for the next interrupt


That was my first approach; the code ended up a bit too messy: it was a state machine and it had to keep track of a bit too many state variables; I rewrote it and the code looks a bit cleaner now. It isn't cast in stone that this will be my final implementation maybe I'll go back to your suggestion if I can make a cleaner implemenation.

Thanks for replying and kind regards,

Jos
42  Using Arduino / Programming Questions / Re: is a read/write from/to an uint8_t atomic? on: February 18, 2013, 12:28:22 am
I know what I'm doing

You "know what you're doing" but don't know that eight-bit writes are atomic? This is not very reassuring.

I don't know much about the Atmega internal memory model, that's why I asked here; if it had an internal four bit bus so that nibbles were written and read the read/writes could've been non-atomic; but they are so I'm happy again ;-)

kind regards,

Jos
43  Using Arduino / Programming Questions / Re: is a read/write from/to an uint8_t atomic? on: February 17, 2013, 12:12:14 pm
I do enable the interrupts in my function though

You are enabling interrupts within an interrupt handler? That is a big red flag.

No it isn't, I know what I'm doing (<--- famous last words ;-) My interrupt function is triggered by a falling edge and then it starts decoding an IR signal from a digital pin; that can takes several milli seconds (I simply poll that pin in the interrupt function) and I want the millis() etc. interrupts to go on. At the start of my function I've detached it from the particular interrupt because I don't want it to be called recursively by another falling edge on that pin. b.t.w. I only enable interrupts after I've detached my function from that falling edge interrupt.

kind regards,

Jos
44  Using Arduino / Programming Questions / Re: is a read/write from/to an uint8_t atomic? on: February 17, 2013, 10:50:39 am
A change to a 8 bit variable is atomic. Changes to larger values are not. However, interrupts are disabled during an interrupt service routine, so corruption of a multibyte variable will not occur in the ISR.

Thanks; that's what I wanted to know; I do enable the interrupts in my function though (reading from an IR takes several milli seconds and I want timers etc. to go on). But as long as that single byte is changed atomically, all is fine.

Thanks again for your reply and kind regards,

Jos
45  Using Arduino / Programming Questions / is a read/write from/to an uint8_t atomic? on: February 17, 2013, 09:45:16 am
Greetings,

the title says it all; an interrupt function decodes an IR remote signal and delivers a uint8_t value; the main control flow periodically reads this value and decides what to do; I don't mind reading an older value as long as the value isn't 'corrupted' by my interrupt handler; it can never be corrupt if the reading/writing of this variable is atomic. Is this so?

thanks in advance and kind regards,

Jos
Pages: 1 2 [3] 4