I have been having trouble lately when compiling my programs in atmel studio 7 when the atmega328PB device is selected and I have included header and C files to my project. The problem will strangely go away when I change the device to Atmega328P. If I do this, the program compiles without any errors however every time I want to flash the atmega32pb then when I open the programming menu (Ctrl Shift P) then I need to change the device back to atmega328pb before flashing or else I get a signature error.
This error happened to me a while ago then strangely stopped and everything was working. It now started again and i cannot find the problem. It only happens when i have included C and h files. If i have not included any additional files other than <avr/io.> and delay then it compiles without errors when the atmega328pb device is selected. See pictures below: