Skip to content
This repository was archived by the owner on Jan 29, 2023. It is now read-only.
This repository was archived by the owner on Jan 29, 2023. It is now read-only.

Bug when going from a >20000us period to a <20000us period. The timer period become 4 times greater. #3

@thiagothimotti

Description

@thiagothimotti

Describe the bug

If I set a interval greater than 20000us and then set a smaller than 20000us, I'll have my period 4 times bigger than expected.

Steps to Reproduce

SAMDTimer ITimer(TIMER_TC3);

uint32_t myClockTimer=0,lastMicros=0;

void clock(void)
{	
	myClockTimer=micros()-lastMicros;    //2us come from here
	lastMicros=micros();
}

void setup() {

}

void loop(){
		ITimer.attachInterruptInterval(20005, clock);  //myClockTimer=20003 (20005 minus 2us, it's correct) 
		delay(5000);
		ITimer.attachInterruptInterval(19995, clock);  //myClockTimer=79978(4 times bigger than expected, minus 2us) 
		delay(5000);
}

Expected behavior

The expected behavior was a timer period of 19995us.

Actual behavior

The actual behavior was a timer period 4 times bigger.

Information

Arduino Core v1.8.9
Atmel Studio

Some observations

If I start with 19000us, works fine. Then I go to 21000us, works fine. When I go back to 19000us, the bug happen.
Only noticed when going from a bigger(>20000) to smaller(<20000). And since this happen the smaller won't work anymore.
I'm suspecting some bug with the preScaler.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions