Kirjoitusalusta.fi
Koko ruutu

Server Notice:

hide

Julkinen työtila Latest text of pad hacklab-ledcontrol Tallennettu Huhtikuu 5, 2012

 
     
Links and info related to creating PWM and other ways to control LED colors.
 
Bit Angle Modulation (BAM) vs. PWM:
Mirror Imaged Bit Angle Modulation (MIBAM):
 
Muita pwm algoritmejä:
 
Driver IC:s & Ardu-code:
  • using 3 to drive RGB https://github.com/rambo/pca9635RGB (a lot of optimizations to be done when I get that far [like writing all changes in single transactions as these ICs support mode where they change outputs synchronously on I2C STOP)
 
RGB Ledejä:
  • $25 / 100 diffuse common anode RGB LEDs, jne
 
 
//// suovulan temppi:
 
Gammaramp 2.5  [256] ja [1024]
 
 
Ledejä esim:
2 ohm vastus, ~4V power supply
 
 
----------
 
// Software PWM
 
ISR(TIMER1_OVF_vect) {          // interrupt service routine that wraps a user defined function supplied by attachInterrupt
  //Timer1.isrCallback();
}
 
void setup() {                
 
  pinMode(13, OUTPUT);     
  
  // Set Timer1, TCNT1, to 16 MHz
  // This will break Arduino's analogWrite to pins X and Y 
  cli();    // disable interrupt
  TCCR1A = 0;                                 // No PWM is used.So set this to zero.
  TCCR1B = 0 << CS12 | 0 << CS11 | 1 << CS10;                             // Input clock is set to clk_io/1 (No prescaling)
  TIMSK1 = 1 << TOIE1;                       // Bit 0 – TOIE1: Timer/Counter1, Overflow Interrupt Enable
  TCNT1 = 0x0000;      // Reset timer counter       
  sei();  // enable interrupts
 
  
}
 
int pwmRampDelta = 1;
uint16_t pwmRampValue = 1;
uint16_t pwmRampValueMax = 1024;            // 0..65535
 
void loop() {
  
  pwmRampValue += pwmRampDelta;
  if (pwmRampValue == 0 || pwmRampValue == pwmRampValueMax) {
    pwmRampDelta = -pwmRampDelta;
  }
  
  uint16_t ticks = TCNT1;
 
  if (pwmRampValue < ticks) {
    digitalWrite(13, HIGH);
  } else {
    digitalWrite(13, LOW);
  } 
  
}