Go Down

Topic: Create a Class - Error  (Read 1 time) previous topic - next topic


I am tring to create a class that setsup the ADC, A Timer and so...
I am tring to create also a class that for example turns a LED on, or off using methods.

The problem is that it does not compile for the arduino.
It says that there is a problem with the method like ADC, when I am tring to use it.

I have tried to include different headers but it didnt work.

please help.

For example: Header file
Code: [Select]

class SetupClass
int Calculate_Register_Value(int Desired_Freq);
void ADC_Timer();
void ADC();
void DAC(int Resolution);
void Serial_Timer();



Then let look at the CPP
Code: [Select]

void SetupClass::ADC()
PMC->PMC_PCER1 |= PMC_PCER1_PID37;  // ADC power on

NVIC_EnableIRQ(ADC_IRQn); // enable ADC interrupt vector

ADC->ADC_IDR = 0xFFFFFFFF; // Disables all interrupts
ADC->ADC_IER = 0x80; // Enable End-Of-Conversion interrupt on Channel 7 -> A0

ADC->ADC_CHDR = 0xFFFFFFFF; // Disables all channels
ADC->ADC_CHER = 0x80; // Enable channel 7

ADC->ADC_MR = ADC->ADC_MR & 0xFFFFFFF0; // Disable Trigers | 4 lowesr bits of ADC_MR
ADC->ADC_MR = ADC->ADC_MR | 0x2; // TRGEN on => External trigger
ADC->ADC_MR = ADC->ADC_MR | 0x1; // TIOA Output of the Timer Counter Channel 0

ADC->ADC_MR = ADC->ADC_MR & 0xFFFFFFEF; // 12-bit resolution

Then in the Arduino IDE:
Code: [Select]

SetupClass Setup;

void setup()
     Setup.ADC(); // Here is a problem and I dont know why.

I have tried to include many files like:
Code: [Select]

#include "Arduino.h"
#include "wiring_analog.h"
#include "wiring_digital.h"
#include "ControlClass.h"
#include "pmc.h"
#include "component_adc.h"
#include "tc.h"
#include "wiring_constants.h"
#include "dac.h"
#include "pins_arduino.h"



I actualy know how to write in OOP. The problem is the compilation doesnt work.
I belive I need to include specfice headers and I dont now what.


Sep 14, 2019, 04:57 pm Last Edit: Sep 14, 2019, 05:00 pm by oqibidipo
ADC is defined as a macro, so you will have to rename SetupClass::ADC to something else. You can't use "Adc" either as it will cause a conflict when expanding ADC.


Ok I have tried this too and then I get and error with this line:

Code: [Select]

NVIC_EnableIRQ(ADC_IRQn); // enable ADC interrupt vector


Sep 15, 2019, 01:42 pm Last Edit: Sep 15, 2019, 01:43 pm by oqibidipo
Code: [Select]
#include <sam.h>

<Arduino.h> includes it, too.

Go Up