gfvalvo:
As written, that code is incompatible with a Due. It uses register names and resources of an AVR processor. The Due is based on an Atmel SAM3X8E.
the code is different or we can just add some library ?
nitrof:
Search for DueTimer into the library manager. it enable interrupt timer for DUE, the code should be more easy to adapt after...
i have read on github about DueTimer , what function should i use to make an AC frequency counter?
I did not play much with timer like this, but here waht I would do:
you can start a timer a low frequency, or short period if you want... :
Timer3.start(1000); // Calls every 1ms
your ISR could increment a counter.
I do not know how you get the input, but the code seem to suggest that you check for the tension to cross 0V.
attachInterrup should be the same.
At that point, you can chec how many counter value ( so uSec ) you have and reset your counter...
I can see two methods to retrieve frequency of an periodic AC signal with the DUE (providing this signal is strictly between 0V and 3.3V):
1/ Use the window feature of the ADC peripheral: trigger an interrupt each time the input signal crosses an high threshold, measure time (e.g. with micros()) between two triggers
2/ Depending on the amplitude of the signal, if close to 3.3V, connect the input to a digital schmitt trigger input and use a simple attachinterrupt() function. You will find Schmitt trigger digital pins page 12 of Sam3x datasheet.
ard_newbie :o I didn't knew that the DUE have an internal schmitt trigger!!! cool to know !! And lokking at the data sheet... it is many !! cool. Maybe the note should be added to DUE pinout diagram?? (BTW onedhaid, Very nice reference to work with DUE. )
ard_newbie, I will try to look for more detail about detail about the schmitt trigger property. I'm curious. Unless you can already point me to the right page... (still a 1400 pae long data sheet.. lol)
I really like this idea.
[EDIT] Unless mistaken, I think I found it: 31.5.9 Input Glitch and Debouncing Filters, P624.