I have a working sketch ( written by Richard Visokey - AD7C) for a VFO (with a DDS AD9850 ) on a Arduino UNO .
I try to adapt and rewrite this sketch for a MEGA2560
I have problems with the interrup . On the UNO Richard use D2 & D3 as connections for the Rotary encoder . I will use D18 & D19 on the MEGA .
This are the original line for the UNO
ISR(PCINT2_vect) {
unsigned char result = r.process();
if (result) {
I changed the Rotary and pinmode lines to 18 & 19 but I can still not use the rotary encoder.
Can someone help me change the code for a MEGA as I do not understand the meaning of PCICR.......PCINT2......
Thank you , I have downloaded several data sheets , and I did it again now .
Sorry but , your download is a simple device overview . What do I have to do whit that ?
Marco.
Yea, it's big. Only look at the chapters you need to The register naming conventions are very similar to the processor in the Uno, there's just more of them. So, a comparison of the relevant sections between the ATmega2560 and ATmega328P datasheets would take a lot less time than reading the whole thing. A Google search fro 'pin change interrupts atmega2560' might also prove helpful.
ISR(PCINT2_vect) {
unsigned char result = r.process();
if (result) {
and replaced it by :
attachInterrupt(digitalPinToInterrupt(18),Down,CHANGE);
attachInterrupt(digitalPinToInterrupt(19),Up,CHANGE);
}
void Up(){
unsigned char result = r.process();
result == DIR_CW;
Opstart=Opstart+increment;
delay(100);
Serial.println(increment);Serial.println(Opstart);
};
void Down(){
unsigned char result = r.process();
result == DIR_CCW;
Opstart=Opstart-increment;
I made this little code . Interrupts are working now but the frequency change ( up or down ) is more a random logic.
Istead a change by 100 ( should be 100, 1000 or 10000 following the status of some ports ) the change is mostly a multiple of 100 ( very bizar )
I don't know if the new lines are all I need or if there is more to control the interrupts.
The original code used pin change interrupts (PCINT) - on the Uno every pin is usable with pin change
interrupts, on the Mega only a few pins work with PCINTs. So changing to direct INT handlers as you've
done is the way to go - the Mega has more INT-capable pins than the Uno so there's less need for pin change
interrupts anyway.
Pin change interrupts monitor a whole port (upto 8 pins) simultaneously, but don't tell you which pins
changed.