Timestamp issues with Arduino Uno (328p)

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
AbeFM
Posts: 16
Joined: Sat Jun 04, 2016 8:03 pm
Has thanked: 2 times

Timestamp issues with Arduino Uno (328p)

Post by AbeFM »

I've got like half a day into this, and am at a loss:

In simulation, I can have a routine that uses the Time/Get-Millisecs function, which fills my array and works ok.

In hardware, I can get the ISR to run, it'll flash a light, etc, as needed. But I'm not sure if my values are making it into my array. If I turn a light on based on the values in the array, I'm lead to believe there's never anything being written.

How do I tell what's wrong? Is there a better way (without Ghost hardware) to see what's in my arrays? I thought there was two-way communication possible with the Arduino, but am not sure the best way to get that working under Flowcode....

Thanks!

AbeFM
Posts: 16
Joined: Sat Jun 04, 2016 8:03 pm
Has thanked: 2 times

Re: Timestamp issues with Arduino Uno (328p)

Post by AbeFM »

Doing a bit more digging: There's a command millis() (see https://www.arduino.cc/en/Reference/Millis) which looks like it should do the same thing, but I'm not sure how to put it in. If I put it in as C, it says the variable I'm using is undeclared (though it works in other spots in the code). If I put it in as a calculation, it's not recognized.

I would think the built in command would call this one, but I'm still seeing no evidence of it working.

AbeFM
Posts: 16
Joined: Sat Jun 04, 2016 8:03 pm
Has thanked: 2 times

Re: Timestamp issues with Arduino Uno (328p)

Post by AbeFM »

I tried putting the line in as C code, and while I'm not sure I'm doing it right, it looks like my problem stems from it not being declared/included?

It precompiles to:

// C Code
// C Code:
/*
Enter C code below this comment
*/
FCV_IGNEVENTTIMESTAMP = millis();

which looks reasonable to me, but I get this error when I compile:
RPM_Decision.c:(.text+0x728): undefined reference to `millis'

Bringing the code into Arduino directly doesn't work, and I'm not sure where to look next.

Please point me in the right direction....

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Timestamp issues with Arduino Uno (328p)

Post by Benj »

Hello,
RPM_Decision.c:(.text+0x728): undefined reference to `millis'
This is saying that the compiler cannot find the code for the millis function.

The source C code for the functions can be found here and can be added to your project via the Build -> Project Options -> Supplementary Code.
https://ucexperiment.wordpress.com/2012 ... -function/

AbeFM
Posts: 16
Joined: Sat Jun 04, 2016 8:03 pm
Has thanked: 2 times

Re: Timestamp issues with Arduino Uno (328p)

Post by AbeFM »

So how exactly does one go about putting this function in so that it can be used?

There's no single paste-this-in thing I can see. I've been trying to divide up the various statements in the post into what goes into which box, and getting a variety of errors.

The linked info makes it straightforward to get this running in the Arduino IDE, but in Flowcode it seems like another day of cutting/pasting/randomly flailing.....

Can you make some step-by-step instructions, or at least group stuff by "paste this in this box" and "change this to that" or something. I'm sure I can figure it out once it's working, but right now I'm not seeing how to use the millis() command in a program that will compile.

Specifically, I'm having issues with undeclared variables - I need globals but there's a naming convention mismatch as FC adds some characters to the beginning, making the c-code incompatible with the rest of the program. That's my guess. :-)

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Timestamp issues with Arduino Uno (328p)

Post by Benj »

Hello,

Porting code from one compiler or IDE to another is probably one of the harder aspects of coding. It's usually a case of keep going until you get rid of all the compilation errors.

Here is a program containing the millis function which is compiling. Hopefully it will also work correctly on hardware, note no simulation due to the C code.
ArdMillis.fcfx
(6.21 KiB) Downloaded 549 times

AbeFM
Posts: 16
Joined: Sat Jun 04, 2016 8:03 pm
Has thanked: 2 times

Re: Timestamp issues with Arduino Uno (328p)

Post by AbeFM »

Ah, thanks Ben! It's going to take a little review to get why yours compiles and mine doesn't, but it looks reasonable enough.

I guess putting "add timers as components" in the feature suggestions is obvious? :-)

Pactor
Posts: 61
Joined: Sat Apr 11, 2015 12:07 pm
Has thanked: 20 times
Been thanked: 14 times

Re: Timestamp issues with Arduino Uno (328p)

Post by Pactor »

I tried the ArdMillis.fcfx and no errors appeared and it was printing a zero all the time on the LCD of my Uno, if that's any help to anyone.
I've no idea what its mean to do.

Mark

AbeFM
Posts: 16
Joined: Sat Jun 04, 2016 8:03 pm
Has thanked: 2 times

Re: Timestamp issues with Arduino Uno (328p)

Post by AbeFM »

I don't have an LCD yet, and haven't taken the time to write something to get it to put out numbers on just plain binary LED's yet.



Aside:
On the original project, I just made my own 3 line clock, work in 0.978... ms clock ticks, and it seems fine. I've yet to test for/figure out what happens with interrupts being enabled/disabled.

The whole attraction to Flowcode to me was the ability to simulate in order to speed up development. So far, it seems if a project requires timing you can't simulate it. Same for using an (unknown) fraction of the standard arduino commands.

With real clear instructions on how to use external C code, so it works by following a cut-and-dried procedure, this could be ok. But if I have to ask the forums to write it for me each time, I am not saving time in development.

Would I be better off using a better supported chip? If arduino is kinda only supported for canned projects, fine. Maybe I'm expecting a bit much here, but something like "Record the time between two events and flip a pin state based on that time" should be close to a drag-and-drop exercise?

I'm still trying to figure out the best way to approach a problem like this. I'm an old LabView hand, and while I often have to spend a while digging through documentation, most of the time, if I read it I can program what I want. I'm at a loss with FlowCode how to find out answers to what I'd consider reasonable questions. Not so much a class on the joys of programming, but rather a list of commands and situations and how to get them working, unambiguously.
I'll try to test this on my hardware and see if I can tell if it's working.

AbeFM
Posts: 16
Joined: Sat Jun 04, 2016 8:03 pm
Has thanked: 2 times

Re: Timestamp issues with Arduino Uno (328p)

Post by AbeFM »

Ok, I added some debug stuff (there's a better way to set debug flags, no?), and it seems I get the same result as Mark - millis() seems to be returning "0".

I tried changing "mils" to an unsigned long (what millis is supposed to return as I understand it) - and I changed the chip type to 328p SMD (that's just what I have).

It seems to count up a debug loop counter just fine, but no timestamps.

Closer, for sure! Where to go next? Thanks guys for the help so far.

-Abe.

Post Reply