Show Posts
Pages: [1]
1  Using Arduino / Project Guidance / attiny85 battery power on: October 17, 2011, 06:31:19 pm
Hey guys,

I'm using an attiny85 for a bike light project. I plan to use either one 3.7v lion battery or 3 AAs to power the project.

I was wondering if I can just go ahead and directly power the attiny with the battery or if there should be some sort of capacitor in the setup somewhere?

I searched around but couldn't find any mention of this but seem to remember reading it somewhere.

Thanks
Mark
2  Using Arduino / LEDs and Multiplexing / Re: Powering 200W LEDs on: October 17, 2011, 04:33:36 pm
Actually... I think this is a lot easier than you think.

I'm pretty sure your LED strips already have resistors in place. You don't actually need to amplify the PWM signal at all, you just need a component on each PWM output capable of switching a much larger source.

You're just going to need a transistor (there are many many articles about these) and a 12v supply capable of putting out 200w.

Ohms law says 200w @ 12v is 16.67 amps... maybe there is a better way to do it though. I think this is a start!

I'd say start with 1 strip of LEDs and then graduate up to the larger project smiley
3  Using Arduino / LEDs and Multiplexing / Re: attiny85 software pwm on: October 16, 2011, 11:33:47 pm
Ok. I figured it out. It's possible and looks fantastic. It only took me like 25 hours. smiley-wink

As soon as I clean the code up a bit I will post it. 5 channel software PWM on this little chip, I love it.

4  Using Arduino / LEDs and Multiplexing / Re: attiny85 software pwm on: October 15, 2011, 08:18:32 am
Hi everyone, I've still been trying to achieve this. I found the following code here http://jaywiggins.com/2011/05/attiny-software-pwm-to-drive-rgb-led/

I used the Arduino IDE to write it to my attiny85 and voila it works. Now I need help figuring out how it works! smiley I understand what's going on here about half the time but the other half where the code gets in to registers and what not leaves me kinda scratching my head.

If someone could help me out with a bit of explanation here so I might begin hacking I'd appreciate it.

Code:
// based largely on Atmel's AVR136: Low-Jitter Multi-Channel Software PWM Application Note:
// http://www.atmel.com/dyn/resources/prod_documents/doc8020.pdf

#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>

#define CHMAX 3 // maximum number of PWM channels
#define PWMDEFAULT 0x00 // default PWM value at start up for all channels

#define RED_CLEAR (pinlevelB &= ~(1 << RED)) // map RED to PB0
#define GREEN_CLEAR (pinlevelB &= ~(1 << GREEN)) // map GREEN to PB1
#define BLUE_CLEAR (pinlevelB &= ~(1 << BLUE)) // map BLUE to PB2

//! Set bits corresponding to pin usage above
#define PORTB_MASK  (1 << PB0)|(1 << PB1)|(1 << PB2)

#define set(x) |= (1<<x)
#define clr(x) &=~(1<<x)
#define inv(x) ^=(1<<x)

#define RED PB0
#define GREEN PB1
#define BLUE PB2
#define LED_PORT PORTB
#define LED_DDR DDRB

void delay_ms(uint16_t ms);
void init();

unsigned char compare[CHMAX];
volatile unsigned char compbuff[CHMAX];

int r_val = 0x00;
int g_val = 0x55;
int b_val = 0xAA;
float dim = 1;

int main() {
  init();
 
  int r_dir = 1;
  int g_dir = 2;
  int b_dir = 4;
 
  for(;;) {
    if (r_val > 254 - 1) {
      r_dir = -1;
    }
    if (r_val < 1 + 1) {
      r_dir = 1;
    }

    if (g_val > 254 - 3) {
      g_dir = -2;
    }
    if (g_val < 1 + 3) {
      g_dir = 2;
    }

    if (b_val > 254 - 4) {
      b_dir = -4;
    }
    if (b_val < 1 + 4) {
      b_dir = 4;
    }
   
    r_val += r_dir;
    g_val += g_dir;
    b_val += b_dir;

    compbuff[0] = r_val;
    compbuff[1] = g_val;
    compbuff[2] = b_val;

    delay_ms(50);
  }
}


void delay_ms(uint16_t ms) {
  while (ms) {
    _delay_ms(1);
    ms--;
  }
}

void init(void) {
  // set the direction of the ports
  LED_DDR set(RED);
  LED_DDR set(GREEN);
  LED_DDR set(BLUE);
 
  unsigned char i, pwm;

  CLKPR = (1 << CLKPCE);        // enable clock prescaler update
  CLKPR = 0;                    // set clock to maximum (= crystal)

  pwm = PWMDEFAULT;

  // initialise all channels
  for(i=0 ; i<CHMAX ; i++) {
    compare[i] = pwm;           // set default PWM values
    compbuff[i] = pwm;          // set default PWM values
  }

  TIFR = (1 << TOV0);           // clear interrupt flag
  TIMSK = (1 << TOIE0);         // enable overflow interrupt
  TCCR0B = (1 << CS00);         // start timer, no prescale

  sei();
}


ISR (TIM0_OVF_vect) {
  static unsigned char pinlevelB=PORTB_MASK;
  static unsigned char softcount=0xFF;

  PORTB = pinlevelB;            // update outputs
 
  if(++softcount == 0){         // increment modulo 256 counter and update
                                // the compare values only when counter = 0.
    compare[0] = compbuff[0];   // verbose code for speed
    compare[1] = compbuff[1];
    compare[2] = compbuff[2];

    pinlevelB = PORTB_MASK;     // set all port pins high
  }
  // clear port pin on compare match (executed on next interrupt)
  if(compare[0] == softcount) RED_CLEAR;
  if(compare[1] == softcount) GREEN_CLEAR;
  if(compare[2] == softcount) BLUE_CLEAR;
}

THANKS EVERYONE!
5  Using Arduino / LEDs and Multiplexing / attiny85 software pwm on: October 13, 2011, 03:25:06 pm
Hi guys,

I'm using the Arduino IDE with my attiny85 chip to make a bike light with 5 LEDs. I want the light to have several modes, one of them being cylon mode (fade back and forth).

I just realized that the attiny only has two pwm channels in HW, and I have NO IDEA how to get started implementing this in software. I've been googling all day but the C examples I've found aren't helping me. I know this is possible because BlinkMs use the same chip and have three channels of PWM.

Can someone help me with basic PWM code?

Thanks everyone.
Pages: [1]