VS Arduino
Visual Micro >> Installation & Troubleshooting >> Arduino Due: Setting Up Timers
https://www.visualmicro.com/forums/YaBB.pl?num=1424887875

Message started by d.gelman on Feb 25th, 2015 at 6:11pm

Title: Arduino Due: Setting Up Timers
Post by d.gelman on Feb 25th, 2015 at 6:11pm
Hello, Community.

I am new to Visual Micro and very excited. I have developed my application using the standard IDE for the Due (currently 1.6).

I use a series of timers, where by I using the following code. This code was provided on the Arduino Forums and I have been very successful with it. It works just fine in the Arduino IDE.


Code (c++):

// ISR flags
volatile int flagOne = 0;

void setup() {
       startTimer(TC1, 0, TC3_IRQn, 100);  //Initialize Timer
}

// Enable Timer
void startTimer(Tc *tc, uint32_t channel, IRQn_Type irq, uint32_t frequency) {
     pmc_set_writeprotect(false);
     pmc_enable_periph_clk((uint32_t)irq);
     TC_Configure(tc, channel, TC_CMR_WAVE | TC_CMR_WAVSEL_UP_RC | TC_CMR_TCCLKS_TIMER_CLOCK4);
     uint32_t rc = VARIANT_MCK / 128 / frequency; //128 because we selected TIMER_CLOCK4 above
     TC_SetRA(tc, channel, rc / 2); //50% high, 50% low
     TC_SetRC(tc, channel, rc);
     TC_Start(tc, channel);
     tc->TC_CHANNEL[channel].TC_IER = TC_IER_CPCS;
     tc->TC_CHANNEL[channel].TC_IDR = ~TC_IER_CPCS;
     NVIC_EnableIRQ(irq);
}

// TC3 Timer Interrupt Handler
void TC3_Handler()
{
     TC_GetStatus(TC1, 0);
     flagOne = 1;
}


As I then ported into Visual Micro, I am getting a red line error when I initialize the timer noting
"Error: expression preceding parentheses of apparent call must have (pointer-to-) function type"

I am reaching out to ask how to fix this, and possibly explain why porting this code into C# breaks it. I am VERY new to C#.

Thank you all.
dgelman

Title: Re: Arduino Due: Setting Up Timers
Post by Visual Micro on Feb 25th, 2015 at 7:11pm
Hi,

Thanks for the post. Actually in Visual Studio we are using C++ same as Arduino. C# is for windows applications.

I suspect the breakage is to do with the attempt to intialise debug which will use the Arduino Serial comms. The Serial is tied closely to timers so hopefully that is the issue.

Please un-tick "tools>visual micro>automatic debugging" and try again

If it fails please zip your sketch and email to info [at] visualmicro.com

Thanks

Title: Re: Arduino Due: Setting Up Timers
Post by d.gelman on Feb 25th, 2015 at 9:09pm

Tim@Visual Micro wrote on Feb 25th, 2015 at 7:11pm:
Hi,

Please un-tick "tools>visual micro>automatic debugging" and try again

Thanks


Thank you for the instructions, unfortunately when I go to Tools>Visual Micro(1.6), I do not see the Automatic Debugging feature.

Please refer to the attachment.
printscreen.png ( 170 KB | 7 Downloads )

Title: Re: Arduino Due: Setting Up Timers
Post by Visual Micro on Feb 25th, 2015 at 9:16pm
Hi,

Sorry I didn't read your message properly earlier.

Actually if you try to compile and upload you will find it works just as the arduino ide does

The intellisense system is disconnected from the compiler because normally Visual Studio does not cater for Arduino projects. Visual Micro takes over and performs the compile and not Visual Studio.

So the error you are seeing does not break anything it probably just shows an incompatibility between Microsoft C++ and Gcc C++ (Arduino uses gcc)

The Timer functions are the ones that often cause intellisense issues and we haven't look at them for the Due for a while.

To save some time email your sketch and we can find a solution.

In the meantime you can also open the "Error List", right click and switch off intellisense errors. This will then give you a clean error list when you compile. An example of the error list is in the release notes for the last release

Title: Re: Arduino Due: Setting Up Timers
Post by d.gelman on Feb 25th, 2015 at 9:58pm
Ah okay, thank you.

I actually never did try to compile, it does work. Is it safe to assume that if the code works on the Arduino IDE, Visual Micro will work, even if errors are shown? I ask this because I notice other red lines including:

1) "Error: identifier "strtok_r" is undefined", when using strtok_r()
2) "Error: expression must have a constant value", when initializing int array with a variable length

Additionally, I am checking the timers and it seems to be working as expected.

With all this said, what would you like to see? The program is fairly large.

dgelman

Title: Re: Arduino Due: Setting Up Timers
Post by Visual Micro on Feb 27th, 2015 at 8:49pm
Hi,

Sorry for the delay.


Quote:
Is it safe to assume that if the code works on the Arduino IDE, Visual Micro will work, even if intellisense errors are shown


Yes and the code remains the same so can be edited in either visual micro or the arduino ide.

...

Can you please zip and email your sketch and sources to info [at] visualmicro.com

Thanks



Title: Re: Arduino Due: Setting Up Timers
Post by d.gelman on Mar 2nd, 2015 at 4:16pm
Thank you very much,

I disabled IntelliSense Errors, but it only removed errors in the error list. Is it possible to hide these types of errors in the actually code? I am still getting many red lines that are fairly distracting.

Regarding sending you the code - it is fairly long and involved. What would you specifically want to see? or would you like everything?

Thanks,
Daniel

Title: Re: Arduino Due: Setting Up Timers
Post by Visual Micro on Mar 2nd, 2015 at 10:08pm
Just an example will do. For example, I guess the error in your screen shot is due to the definition of Tc, the first param?

Any example that will show a few errors will help for now thanks


VS Arduino » Powered by YaBB 2.6.12!
YaBB Forum Software © 2000-2025. All Rights Reserved.