ADC convertion with internal ref and interruption

userHead anonymous 2022-06-01 14:57:27 590 Views1 Replies
Hi,
I'm using a LattePanda for a project and i have some issue to make an AD convertion with timer interrupts and internal reference.
I'm using the LattePanda V1 Leonardo. The timer interrupt work fine but my probleme is that my ADC Value never change.

I also have an arduino uno on which the conversion works perfectly.
Is there that much difference between an arduino uno and an arduino leonardo?

You will find the code i use below :

Code: Select all

#include <Arduino.h> const byte Led = 13; volatile int readFlag; volatile int valADC = 0; float valVolt; const int TempoTimer = 10; #define LedToggle digitalWrite (Led, !digitalRead(Led)) ISR(ADC_vect) { valADC = ADCL | (ADCH << 8); readFlag = 1; LedToggle; } ISR(TIMER1_OVF_vect) { TCNT1 = 65536 - TempoTimer; //LedToggle; } void setupADC() { // //ADC Channel---\\\\\ --> Channel A0 //Ajustement---\||||| --> Right //Ref Sel----\\|||||| --> Internal Ref // |||||||| ADMUX = 0b11000000; //Prescaler----------\\\ --> Xtal/2 = 16MHz/2 = 8MHz; //ADC INT Enable----\||| --> Enable interrupt //Auto Trigger----\||||| --> Enable //Start Conv-----\|||||| //Enable--------\||||||| --> ADC Enable // |||||||| ADCSRA = 0b10101111; //Source AutoTrig---\\\\ --> Timer1 Overflow //MUX5------------\ |||| --> Channel A0 //HS Mode-------\ | |||| // | | |||| ADCSRB = 0b00000110; // Start conversion // ADCSRA |= 0b01000000; } void setupTimer1() { bitClear (TCCR1A, WGM10); // WGM10 = 0 bitClear (TCCR1A, WGM11); // WGM11 = 0 bitClear (TCCR1B, WGM12); // WGM10 = 0 bitClear (TCCR1B, WGM13); // WGM11 = 0 TCCR1B = 0b00000100; // Clock / 256 soit 16 us TIMSK1 = 0b00000001; // Local Interrupt TOIE1 TCNT1 = 65536 - TempoTimer; } void setup() { /* Port Setup */ //pinMode(A0,INPUT); //Pin à Mesurer cli(); // Désactive l'interruption globale /* ADC Setup */ setupADC(); /* Timer 1 Setup */ setupTimer1(); sei(); // Active l'interruption globale; Serial.begin(115200); } void loop() { if (readFlag == 1) { Serial.println(valADC); valVolt = valADC * (2.56/1023.0); //Serial.println(valVolt); Serial.print("Mesure : "); Serial.print(valVolt); Serial.println(" V"); readFlag = 0; } } Thanks for helping me and sorry for my bad english.