Dennis-van-Gils / SAMD51_InterruptTimer

SAMD51 Interrupt Timer library for e.g. Adafruit M4 Metro/Feather/ItsyBitsy Express
MIT License
25 stars 7 forks source link

48 MHz? #1

Closed jamman83 closed 4 years ago

jamman83 commented 4 years ago

Hey, thanks for the library, exactly what I needed.

This isn't an issue, more of a question: you define CPU_HZ as 48 MHz. Isn't the CPU at 120 MHz? I understand the timer may ultimately using DFLL48M as clock source, but if that's the case shouldn't it be called TIMER_HZ or something?

TinManAkshay commented 4 years ago

Yes I noticed the same thing. I am using Adafruit feather M4 express and I am using this library. But I couldn't get the interrupt timer working. Can you please help me out? Have you made any changes?

Thanks, Akshay

jamman83 commented 4 years ago

Worked as is for me, you'll have to be a little more specific. Did you run the example code?

TinManAkshay commented 4 years ago

No I have not tried that example yet. I have my own code written for the sensor where I have an interrupt function which i am calling inside void setup(). I am following the same format for the interrupt timer as written in the example code. So when i run my code and observe the output in serial monitor (Arduino IDE), its stuck after the point where I call my interrupt function. My understanding so far is that its not reaching inside the interrupt function.

What are your thoughts as in, what could be the issue behind this library not working?

jamman83 commented 4 years ago

Post the full code or at least your setup. I don't quite get what you mean you're calling an interrupt in setup.

TinManAkshay commented 4 years ago

This is the code and timer statement is in bold format down below.

_void setup() { // put your setup code here, to run once: /Wire.begin(); Serial.begin(9600); delay(3000); Serial.println("\n Welcome to Heimann 88 sensor"); Serial.println("\n Configure the sensor"); sensor_config();*/ pinMode(SDA, INPUT); pinMode(SCL, INPUT); digitalWrite(SDA, HIGH); digitalWrite(SCL, HIGH);

// begin serial communication Serial.begin(115200); while (!Serial) { ; }

// begin I2C communication ( 1000kHz - sensor) Serial.print("search device"); uint8_t error; while (error != 0) { Wire.end(); delay(2000); Wire.begin(); Wire.beginTransmission(SENSOR_ADDRESS); error = Wire.endTransmission(); Serial.print("."); }

Wire.setClock(CLOCK_SENSOR); // HINT: To increase the frame rate, here the I2C clock is higher than 1MHz from datasheet. If this causes any problems, set to the datasheet value.

Serial.print("\nread eeprom"); read_complete_eeprom();

Serial.print("\nwake up sensor"); // to wake up sensor set configuration register to 0x01 // | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | // | RFU | Start | VDD | BLIND | WAKEUP | // | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | write_sensor_byte(SENSOR_ADDRESS, CONFIGURATION_REGISTER, 0x01);

Serial.print("\ninitialization"); write_calibration_settings_to_sensor();

Serial.print("\nstart sensor"); // to start sensor set configuration register to 0x09 // | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | // | RFU | Start | VDD | BLIND | WAKEUP | // | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 1 | write_sensor_byte(SENSOR_ADDRESS, CONFIGURATION_REGISTER, 0x09);

// other calculations before main loop gradscale_div = pow(2, gradscale); calculate_pixcij();
timer_duration = calc_timer_duration(bw, clk_calib, mbit_calib); //TimerLib.setInterval_us(readblockinterrupt, timer_duration); TC.startTimer(timer_duration, readblockinterrupt);

// ERROR TABLENUMBER if (tablenumber != TABLENUMBER) { Serial.print("\n\nHINT:\tConnected Sensor does not match the selected look up table."); Serial.print("\n\tThe calculated temperatures could be wrong!"); Serial.print("\n\tChange device in sensordef_16x16.h to sensor with tablenumber "); //Serial.print(tablenumber); } // ERROR BUFFER LENGTH if (BUFFER_LENGTH < 258){ Serial.print("\n\nHINT:\tBUFFER_LENGTH in Wire.h library is not 258 or higher."); Serial.print("\n\tThe calculated temperatures could be wrong!"); Serial.print("\n\tChange BUFFERLENGTH in wire.h to 258 or higher"); } }

jamman83 commented 4 years ago

Can you print out the timer_duration and tell me what it is? Can i see the interrupt as well? There are quite a few things you can't do during an interrupt.

TinManAkshay commented 4 years ago

Timer duration is 23963 us.

and interrupt is:

_**void readblockinterrupt() {

//TimerLib.clearTimer(); // wait for end of conversion bit (~27ms) read_sensor_register( STATUS_REGISTER, (uint8_t)&statusreg, 1); while (bitRead(statusreg, 0) == 0) { Serial.println("status reg check error"); read_sensor_register( STATUS_REGISTER, (uint8_t)&statusreg, 1); }

if (read_block_num == 0) {

read_sensor_register( ARRAY_DATA, (uint8_t*)&data_array, 130);
if (read_eloffset_next_pic == 1) {
  // change block in configuration register (to el.offset)
  // |  7  |  6  |  5  |  4  |   3   |   2   |   1   |    0   |
  // |          RFU          | Start |  VDD  | BLIND | WAKEUP |
  // |  0  |  0  |  0  |  0  |   1   |   1   |   1   |    1   |
  write_sensor_byte(SENSOR_ADDRESS, CONFIGURATION_REGISTER, 0x0B + 0x04);
}
else {
  // change block in configuration register (to data)
  // |  7  |  6  |  5  |  4  |   3   |   2   |   1   |    0   |
  // |          RFU          | Start |  VDD  | BLIND | WAKEUP |
  // |  0  |  0  |  0  |  0  |   1   |   0   |   1   |    1   |
  write_sensor_byte(SENSOR_ADDRESS, CONFIGURATION_REGISTER, 0x09);
}

}

if (read_block_num == 1) { read_sensor_register( ARRAY_DATA, (uint8_t*)&electrical_offset, 130); // change block in configuration register (to data) // | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | // | RFU | Start | VDD | BLIND | WAKEUP | // | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 1 | write_sensor_byte(SENSOR_ADDRESS, CONFIGURATION_REGISTER, 0x09 ); }

read_block_num++;

if ( (read_eloffset_next_pic == 0 && read_block_num == 1) || (read_eloffset_next_pic == 1 && read_block_num == 2)) { state = 1; read_block_num = 0; picnum++;

// read electrical offset next time
if (picnum == 10) {
  read_eloffset_next_pic = 1;
  picnum = 0;
}
else {
  read_eloffset_next_pic = 0;
}

}

//TimerLib.setInterval_us(readblockinterrupt, timer_duration); //TC.startTimer(timerduration, readblockinterrupt); }**

jamman83 commented 4 years ago

Try commenting out the Serial.println("status reg check error"); I know that is an issue, maybe not the issue, but Arduino doesn't like using Serial in interrupts.

TinManAkshay commented 4 years ago

I just tried that. But the data I need from this interrupt, I am not getting that. This data will further be used for the calculations being happened inside the void loop().

jamman83 commented 4 years ago

Without seeing literally the whole project, I can't tell you for sure what's wrong. Its a little tedious, but without a debugger (JST), the best way to debug interrupt code is turn on the led at a line of code, compile and run, then keep moving the led down line by line until you see where it doesn't turn on to find the problem.

TinManAkshay commented 4 years ago

I ll see what's going wrong and where. Thanks a lot for the help. :)

Dennis-van-Gils commented 4 years ago

Closing the issue as the problem seems to be a user-implementation error and that it got resolved. Thanks @jamman83 for your input.