openAST icon indicating copy to clipboard operation
openAST copied to clipboard

Modify arduinoISP to generate clock source for programming of attiny

Open condac opened this issue 6 years ago • 0 comments

Investigate if following code can generate a 4mhz clock and if it works to program a attiny with external clock bit set.

/*
    Prorotype Code for 1-4MHz PWM 50% Duty Cycle
    ICR1 as TOP = crystal / (2*Prescale*Fpwm)    in MODE 9
    
    
    at 16000000MHz   64 Prescale PWM Fmax = 62.5KHz 
    at 16000000MHz    8 Prescale PWM Fmax = 500KHz
    at 16000000MHz    1 Prescale PWM Fmax = 4MHz
    
*/

void setup(){

  pinMode(9, OUTPUT);                              // OCR1A Output
  
  pinMode(10, OUTPUT);                             // Just test LED on OCR1B Generally LED
  digitalWrite(10, LOW);
  delay(1000);
  digitalWrite(10, HIGH);
  
//phase/frequency correct mode. 

TCCR1A = _BV(COM1A1);                                               // Enable OCR1A 
//TCCR1A = _BV(COM1A1) | _BV(COM1B1) ;                      // Enable OCR1A and OCAR1B 
// TCCR1A = _BV(COM1A1) | _BV(COM1B1) | _BV(COM1A0) | _BV(COM1B0); 

//TCCR1B = _BV(WGM13) | _BV(CS11);                                  // Set Prescale Clock 8 and Mode 9
TCCR1B = _BV(WGM13) | _BV(CS10);                                    // Set Prescale Clock 1 and Mode 9
}

void loop(){

//ICR minimum 2   F = 16000000MHz  No Change if using 14.7456MHz very close for fucking lazy bitch. and I don't need precision PWM at all.

16.MHz Xtal for PWM Frequency while 14.7456MHz for Precision Baudrate RS232/RS485/RS422

/*make this variable as table.
//ICR1 = 10,000;                     // 100Hz w/16MHz Prescale 8
//ICR1 = 5,000;                      // 200Hz w/16MHz Prescale 8

//TEST 500MHZ MAX
//ICR1 = 2;                            // 500KHz w/16MHz Prescale 8

// Test 4MHZ  MAX
ICR1 = 2;                                // 4MHz w/ 1600000MHz Prescale 1


OCR1A = ICR1 / 2;                    // 50 Duty of ICR1
}

condac avatar May 03 '18 12:05 condac