Hello
Beginner with Arduino but we used to work with C
We are making a chronometre for motorcycle with an electromagnetic field detector
Each circuit has "bands" under the asphalt that generate an electromagnetic field that allows us to time our laps with maximum precision
We are working on Arduino Due (big card because we are not going to do chronometer only). We will also have an inclinometer that can see the direct angle of the bike as well as the max angles on each side and record the angle permanently to then transcribe it on a curve, an accelerometer to measure the acceleration and braking force which is also recorded to be transcribed on a curve, and a GPS for the real speed wich is recorded to have a curve too.
So we programmed our chronometer and have our field detector (Ref: SS41A)
After a long search, we finally found that we need to work with the ADC_CWR registry but we are unable to access it and find no information to do so.
Here is the link to the Atmel ATSAM3X8E datasheet which is on the DUE, page 1348 for what we think is good:
http://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-11057-32-bit-Cortex-M3-Microcontroller-SAM3X-SAM3A_Datasheet.pdf
Can you help us please ??!
We remain on the lookout to answer you as soon as possible and give you as much information as possible if necessary
Thanking you GREATLY in advance
Jeremy et Remi
ADC_CWR is the ADC Compare Window register.
An example sketch to trigger an interrupt each time an ADC conversion crosses an high threshold:
volatile boolean Flag;
void setup() {
adc_setup();
}
void loop() {
if (Flag == true)
{
Flag = false;
//Do something
}
}
void adc_setup ()
{
PMC->PMC_PCER1 |= PMC_PCER1_PID37; // ADC power ON
ADC->ADC_CR = ADC_CR_SWRST; // Reset ADC
ADC->ADC_MR |= ADC_MR_FREERUN_ON // ADC in free running
| ADC_MR_LOWRES_BITS_12 // 12 bits resolution
| ADC_MR_PRESCAL(1)
| ADC_MR_SETTLING_AST3
| ADC_MR_TRACKTIM(10)
| ADC_MR_TRANSFER(2);
ADC->ADC_EMR = ADC_EMR_CMPMODE_HIGH // Compare with high threshold
| ADC_EMR_CMPSEL(7) // Compare channel 7 = A0
| ADC_EMR_CMPFILTER(10); // Number of consecutive compare events necessary
// to raise the flag = CMPFILTER+1
ADC->ADC_ACR = ADC_ACR_IBCTL(0b01); // For frequencies > 500 KHz
ADC->ADC_CWR = ADC_CWR_HIGHTHRES(4000); // Compare with a high threshold of conversion
ADC->ADC_CHER = ADC_CHER_CH7; // Enable Channel 7 = A0
ADC->ADC_IER = ADC_IER_COMPE; // Interrupt on Compare match enable
NVIC_EnableIRQ(ADC_IRQn); // Enable ADC interrupt
}
void ADC_Handler() { // One Comparison Event has occurred since the last read of ADC_ISR.
ADC->ADC_ISR; // Read ADC_ISR;
ADC->ADC_CDR[7]; // Maybe should be read to allow next interrupt
// Do some stuff (keep this as short as possible, e.g. set a flag to be proceed in loop())
Flag = true;
}
Thank a looooooooot !!!
It works perfectly !!!