// Make clock source for SA1000 board // Uses // https://github.com/SpenceKonde/ATTinyCore // Tools options selected // Board ATtiny 25/45/85 (No bootloader) // Chip ATtiny45 // Clock source 18.432 MHz externa or 9.216 MHz // Timer 1 CPU frequency // LTO (Link time optimization) enabled // mills/micros enabled // EEPROM retained // BOD (brown out detection) 4.3V. // If using a 3.3V board to program the chip will program but not run due to BOD // Programmed using Arduino as ISP. // Used these instructions to wire up programmer. Also wired crystal and 18pf caps to crystal pins // https://www.electronics-lab.com/project/how-to-program-attiny13attiny13a-using-arduino-ide/ // If you don't have the crystal attached after you program bootloader you can't talk to the chip // until you attach a crystal. // Note that most instructions say use pins 10-13. Current code default is 10, MOSI, MISO, and SCK. // If you wired to 10-13 you need to define USE_OLD_STYLE_WIRING in ArduinoISP sketch // Need to switch to board you are using to load the programmer sketch and then // then switch to ATtiny board to tools->burn bootloader then program // sketch->upload using programmer // Sometimes need to burn bootloader twice for it to work. // // PB0 is output clock ckip pin 5 // // Uplaod sketch with upload using programmer. // Target frequency 271250. With 18.432 MHz clock divide toggle every 34 clock // gives 271059 Hz or 0.07% slow. OEM manual says clock needs to be within 0.1% // so good enough. // ************************************************************** // Set this to 34 for 18.432 MHz oscillator. Use 17 for 9.216 MHz unsigned int loop_count_pll = 17; void setup() { // put your setup code here, to run once: pinMode(PB0, OUTPUT); TCCR0B = B00000000;// Stop Timer/Counter0 clock by setting the clock source to none. TCCR0A = B00000000;// Set Timer/Counter0 to normal mode. TCNT0 = 0;// Set Timer/Counter0 to 0 OCR0A = loop_count_pll-1;// Set the Output Compare for Timer/Counter0 TCCR0A = B01000010;// Set Timer/Counter0 to CTC mode. Set OC0A to toggle. TCCR0B = B00000001;// Start Timer/Counter0 clock by setting prescale of PLL source. } void loop() { // put your main code here, to run repeatedly: }