simavr icon indicating copy to clipboard operation
simavr copied to clipboard

Attiny85's PLOCK bit never sets (the PLL never locks)

Open packocrayons opened this issue 3 years ago • 4 comments

The following MWE reproduces the issue:

#include <avr/io.h>
#include <util/delay.h>

int main(){
        PLLCSR = (1 << PLLE);
        _delay_us(100);
        while (! (PLLCSR & (1 << PLOCK)));
        PLLCSR |= (1 << PCKE);
}

Running with simavr and avr-gdb (-ggdb -Og) and a breakpoint on line 8 (the PCKE line), never breaks. The emulator gets stuck on line 7 waiting for "hardware" to set the PLOCK bit to confirm that the PLL is locked

avr-gcc -mmcu=attiny85 -Wall -DF_CPU=8000000 -Og -ggdb -o main main.c

P.S. I would be happy to work on this issue, given a pointer on where to start to emulate the PLL

packocrayons avatar Jan 31 '22 02:01 packocrayons

My guess is that the counter/timer code (avr_timer.*) is the natural home for that. The data sheet documents PLLCSR in the counter/timer section.

This link may be useful: other AVRs with PLL.

gatk555 avatar Feb 02 '22 13:02 gatk555