วันศุกร์ที่ 13 ตุลาคม พ.ศ. 2560

arduino induction cooker

// PWM output @ 25 kHz, only on pins 9 and 10.

// Output value should be between 0 a


void setup()
{
    // Configure Timer 1 for PWM @ 25 kHz.
    TCCR1A = 0;           // undo the configuration done by...
    TCCR1B = 0;           // ...the Arduino core library
    TCNT1  = 0;           // reset timer
    TCCR1A = _BV(COM1A1)  // non-inverted PWM on ch. A
           | _BV(COM1B1)  // same on ch; B
           | _BV(WGM11);  // mode 10: ph. correct PWM, TOP = ICR1
    TCCR1B = _BV(WGM13)   // ditto
           | _BV(CS10);   // prescaler = 1
    ICR1   = 320;         // TOP = 320
     
    
    // Configure Timer 0 for phase correct PWM @ 25 kHz.
    TCCR0A = 0;           // undo the configuration done by...
    TCCR0B = 0;           // ...the Arduino core library
    TCNT0  = 0;           // reset timer
    TCCR0A = _BV(COM0B1)  // non-inverted PWM on ch. B
            | _BV(WGM00);  // mode 5: ph. correct PWM, TOP = OCR0A
    TCCR0B = _BV(WGM02)   // ditto
        | _BV(CS00);   // prescaler = 1
    OCR0A  = 160;         // TOP = 


    // Same for Timer 1.
    

    // Same for Timer 2.
    TCCR2A = 0;
    TCCR2B = 0;
    TCNT2  = 0;
    //TCCR2A = _BV(COM2B0)  // non-inverted PWM on ch. B
     //   | _BV(WGM20);  // mode 5: ph. correct PWM, TOP = OCR2A
    //TCCR2B = _BV(WGM22)   // ditto
    //    | _BV(CS21);   // prescaler = 1
    //  OCR2A  = 160;
     // OCR2B  = 160;
    
    TCCR2B = TCCR2B & 0b11111000 | 0x01;
    TCCR2A = _BV(COM2A1) | _BV(COM2B1) | _BV(WGM20);
    TCCR2B = _BV(CS20);
    OCR2A = 180;
    OCR2B = 180;  

 
    // Set the PWM pins as output.
    pinMode( 9, OUTPUT);
    pinMode(10, OUTPUT);
    pinMode( 3, OUTPUT);
    pinMode(5, OUTPUT);
    pinMode( 6, OUTPUT);
    pinMode( 11, OUTPUT);
    
}

void loop()
{
    // Just an example:
    analogWrite( 9, map (analogRead (0),0,1000,-50,100)); //100);  // duty cycle = 1/16010);
    analogWrite(10, map (analogRead (1),0,1000,0,100)); //100);  // duty cycle = 1/160210);
    analogWrite( 3, map (analogRead (2),0,1000,-100,100)); //100);  // duty cycle = 1/16010);
    analogWrite( 5, map (analogRead (4),0,1000,0,100)); //100);  // duty cycle = 1/160210);

    analogWrite( 6, map (analogRead (3),0,1000,0,100)); //100);  // duty cycle = 1/16010);
    analogWrite( 11, map (analogRead (5),0,1000,-50,100)); //100);  // duty cycle = 1/160210);
   
   
}

ไม่มีความคิดเห็น:

แสดงความคิดเห็น