dbuezas / lgt8fx

Board Package for Logic Green LGT8F328P LGT8F328D and LGT8F88D
362 stars 87 forks source link

Can't handle Timer3 OC3B interrupt #169

Closed danielwsky closed 1 year ago

danielwsky commented 3 years ago

I'm trying to use the OC3B in CTC mode, but when I enable the OCIE3B interrupt, my board don't run anything, feeling like it's stuck on something, but the OC3B works, so I think it doesn't handle the interrupt and because of it, it doesn't clear the interrupt flag. Code (short): void setup() { DDRD |= (0 << DDD2); DDRF |= (1 << DDD2); pinMode(A0, OUTPUT); TCCR3A |= (1 << COM3B1) | (0 << COM3B0) | (0 << WGM31) | (0 << WGM30); TCCR3B |= (0 << CS32) | (0 << CS31) | (0 << CS30) | (0 << WGM33) | (1 << WGM32); OCR3BH = highByte(8000); OCR3BL = lowByte(8000); TIMSK3 |= (1 << OCIE3B); TCCR3B |= (1 << CS32) | (0 << CS31) | (1 << CS30); sei(); }

ISR(TIMER3_vect) { digitalWrite(A0, !(digitalRead(A0))); TCCR3B |= (0 << CS32) | (0 << CS31) | (0 << CS30); TIFR3 |= (1 << OCF3B); sei(); }

I can post the full code if necessary, but I think this is enough. Am I missing something?

I'm using ver 1.0.6

dbuezas commented 3 years ago

I think you are missing the following:

And I see a couple of redundant things:

But you are close!

dbuezas commented 3 years ago

Timers are pain to get right, but you are up for a treat, I'm close to releasing this: image

It's interactive so you can just click your way through it, including 80mA outputs, interrupts, etc. I used this to check most of your code, I may have ported something incorrect from the datasheet, so there may be a bug or two still. Eventually I want to also add the configs for the atmega328p and also support to configure dead time in the lgt chip.

dbuezas commented 3 years ago

follow the progress here: #164

dbuezas commented 3 years ago

Deployed: https://dbuezas.github.io/arduino-web-timers

dwillmore commented 1 year ago

@danielwsky does this address your issue sufficiently? If so, please close this.