solar bird

creating sound with microcontrollers

solar bird

Postby chris on Wed Oct 22, 2008 12:05 pm

Inspired by some sound making solar electronics from Michu and Ralf Schreiber, I decided to try developing a solar sound generator with a small Attiny13 Mikrocontroller.
And "vois la", it was possible to build a small circuit with very view components: An Attiny13 Mikrocontroller, one 3V solar cell, a capacitor and a piezo speaker.
An intersting result of this experiment was that the Mikrocontroller ist spezified for a minimum supply volatag of 1.8V but in reality it is starting up at arround 1.2V. Therefore not much light is needed to operate the circuit. To achieve a minimum power consumption of the microcontroller the internal 128KHz oszillator is used as clock source.

If you want to build a micorontroller solar bird on your own, here is the code:

Code: Select all
/*************************************************************************

   solar bird

   attiny 13 slow clock low power experiments

   28.9.08 christoph(at)roboterclub-freiburg.de

*************************************************************************/
/*************************************************************************

   Hardware
   
   prozessor:   ATtin13
   clock:      128Khz internal oscillator

   PIN1   RESET         
   PIN2   PORTB3/ADC3      
   PIN3   PORTB4/ADC2      
   PIN4   GND

   PIN5   PORTB0/OC10      piezo controll speaker
   PIN6   PORTB1         
   PIN7   PORTB2/ADC1      
   PIN8   VCC

*************************************************************************/
#include <avr/io.h>

#define PIEZOSPEAKER (1<<PINB0)

#define LOADSECONDS 60

#define HZ_1706 2
#define HZ_853 4
#define HZ_586 6
#define HZ_426 8

void init_timer()
{
   /* frequency example
   TCCR0B=0x02; // internal clock source devided by 8
    OCR0A=9; // Compare value
   // caldulated frequency at 9.6MHz: 9.6e6/(2*8*(9+1))= 60kHz , Division by 2 due to toogle
   //TCCR0A=0x02; // CTC-Mode (clear timer on compare match)
   */

   TCCR0A=(1<<COM0A0) | 0x02; //CTC mode and toogle OC0A port on compare match
   TCCR0B=(1<<CS00) ; // no prescaling,
   OCR0A=255; // in CTC Mode the counter counts up to OCR0A
   // CTC-Modefrequency calculation: f=IO_CLC/(2*N*(1+OCR0A)) N:Prescaler
   // e.g. IO_CLK=128KHz, N=1; OCR0A=1 ==> 64Khz
   // e.g. IO_CLK=128KHz, N=1; OCR0A=10 ==> f=6095Hz
   // e.g. IO_CLK=128KHz, N=1; OCR0A=100 ==> f=633Hz
   // e.g. IO_CLK=128KHz, N=1; OCR0A=200 ==> f=318Hz
   // e.g. IO_CLK=128KHz, N=1; OCR0A=255 ==> f=318Hz


   TCCR0B=(1<<CS00) ; // no prescaling,

      
   ///FAST PWM mode and set OC0A ( PB0 ) port on compare match   
   //TCCR0A=(1<<COM0A0) | (1<<COM0A1) | (1<< WGM00 ) | (1<< WGM01 );

   //   TCCR0B=(1<<CS00) | (1<< WGM02 ); // no prescaling, PWM OCR0A update
   //TCCR0B=(1<<CS00) ; // no prescaling,

   //TCCR0B=0x02; // internal clock source devided by 8
    //OCR0A=9; // Compare value

    OCR0A=255; // Counter end   
   // caldulated frequency at 9.6MHz: 1/9.6e6/(8*(124+1))= 9600 Baud
   // bit time = 104,17us
   //TCCR0A=0x02; // CTC-Mode (clear timer on compare match)
}
// duration in 1ms
void delay_ms(uint16_t duration)
{
   uint16_t d;
   uint8_t n;
   uint16_t counter;

   counter=(3*duration);
   // periode duration 586us
   for(d=0;d<counter;d++)
   {
      for(n=0;n<1;n++) PORTB=0;
      for(n=0;n<1;n++) PORTB=0;
   }
}
#define SPEAKEROFF  TCCR0A=(0x02)
#define SPEAKERON    TCCR0A=((1<<COM0A0) | 0x02)
int main(void)
{
   uint16_t n;
   uint8_t counter=100;
   uint16_t phase1;
   uint16_t phase2;
   uint16_t phase3;
   uint16_t t1=100;
   uint16_t t2=10;
   uint16_t t3=1;


   // Ports
   DDRB=PIEZOSPEAKER; // Pins as output
   OCR0A=100;
   init_timer();

   delay_ms(1000);

   while(1)
   {
      //delay_ms(10);
      phase1+=t1;
      phase2+=t2;
      phase3+=t3;
      //t1=phase2;
      if((phase2>>8)==1)t1=100;
      if((phase2>>8)==100) t1=200;
      if((phase3>>8)==1)
      {   
         SPEAKERON;
      }
      if((phase3>>8)==20)
      {   
         SPEAKEROFF;
      }
      OCR0A=255-(phase1>>8);
   }
   return 0;
}
/***************************************************************************
*   
*   (c) 2008 christoph(at)roboterclub-freiburg.de
*
***************************************************************************
*   This program is free software; you can redistribute it and/or modify  *
*   it under the terms of the GNU General Public License as published by  *
*   the Free Software Foundation version 2 of the License,                *
*   If you extend the program please maintain the list of authors.        *
*   If you want to use this software for commercial purposes and you      *
*   don't want to make it open source, please contact the authors for     *
*   licensing.                                                            *
***************************************************************************/
Attachments
SolarBirdHinten_klein.jpg
SolarBirdHinten_klein.jpg (65.63 KiB) Viewed 3858 times
SolarBird1_klein.jpg
SolarBird1_klein.jpg (20.92 KiB) Viewed 3649 times
chris
 
Posts: 260
Joined: Sun May 25, 2008 7:21 am

Re: solar bird

Postby chris on Sun Mar 27, 2011 3:47 pm

Here the MSP430 Version. I tried to use a MSP430 because I got a Ti-Launchpad for free. The solar bird is build with the MSP430G2231 included in the Launchpad kit.

Code: Select all
/*************************************************************************
    solar bird

    low energy experiment

    Use a solar cell to harvest power. Drive the microcontroller.
    drive a piezo speaker to produce some bird like sound.

    V1: 28.9.08   christoph(at)roboterclub-freiburg.de
                  attiny 13 slow clock low power experiments

    V2: 27.3.2011 christoph(at)roboterclub-freiburg.de
                  MSP430 slow clock low power experiments

*************************************************************************/
/*************************************************************************
   Hardware

    3V-solar cell
    220uF capacity ( between DVCC and VSS )
    10k Resistor ( Reset to DVCC )
    piezo speaker

    prozessor:   MSP430G2231

    clock:      ~150Khz internal oscillator

    PIN1    DVCC ( V+  )

    PIN4    PIEZO SPEAKER OUTPUT ( SOUND OUTPUT )

    PIN10   Reset ( connect to DVCC by 10K Resistor )

    PIN14   DVSS ( GND )

*************************************************************************/
#include "msp430g2231.h"
#include "inttypes.h"

#define PIEZO_PIN       BIT2
#define PIEZO_TOGGLE    { P1OUT ^= PIEZO_PIN; }
#define SPEAKERON       P1DIR|=PIEZO_PIN; // switch on sound
#define SPEAKEROFF      P1DIR&=~PIEZO_PIN; // switch on sound

uint16_t TimerPeriod=1000;
/**************************************************************************

init

**************************************************************************/
void init()
{
  WDTCTL = WDTPW + WDTHOLD;         // Stop WDT

  //******** MCU clock setup ***********************
  /*
  // set up clock frequency
  // 0.12MHZ CPU CLK: RRSEL=0 DCO=3 MOD=0
  BCSCTL1&=~(0x0F); //RSEL_0
  DCOCTL = DCO1|DCO0;// DCO_3,MOD=0
  */ 

  // 0.15MHZ CPU CLK: RRSEL=0 DCO=3 MOD=0
  BCSCTL1&=~(0x0F);
  BCSCTL1|=RSEL1; //RSEL_1
  DCOCTL = DCO1|DCO0;// DCO_3,MOD=0

  //******** timer setup ****************************
  //CCTL1 = OUTMOD_7;                 // CCR1 reset/set
  // SMCLK, up mode, SYSCLK/8 = 500KHz @ 16MHZ
  //TACTL = TASSEL_2 + MC_1 + ID_3;
  // SMCLK, up mode, full speed SYSCLK = 150kHz @ 150kHz

  TACTL = TASSEL_2 + MC_1 + ID_0;
  TACCTL0 |= CCIE;          // capture compare interrupt enable
  TACCTL0 |= OUTMOD_7;        // set timer output "toogle"
  CCR0 = 1;
  //******** port pin setup*************************
  P1DIR |= PIEZO_PIN;      // set output pins
  P1OUT = 0;
 
_BIS_SR(GIE);             // global interrupt enable
}
/**************************************************************************

  main

**************************************************************************/
void main(void)
{
  uint16_t phase1=0;
  uint16_t phase2=0;
  uint16_t phase3=0;
  uint16_t t1=100;
  uint16_t t2=10;
  uint16_t t3=1;

  init();

  SPEAKEROFF;
  for(t1=0;t1<60000;t1++); // just a delay
  SPEAKERON;

  while(1)
  { 
    phase1+=t1;
    phase2+=t2;
    phase3+=t3;

    if((phase2>>8)==1)t1=100;
    if((phase2>>8)==100) t1=200;
    if((phase3>>8)==1)
    {
   SPEAKERON;
    }
    if((phase3>>8)==20)
    {
        SPEAKEROFF;
    }

    uint8_t OCR0A; // attiny 13 compatibility
    OCR0A=255-(phase1>>8);
    TimerPeriod=300-OCR0A;

  }
}
//********************** interrupt ***************************************
#pragma vector=TIMERA0_VECTOR
__interrupt void Timer_A0 (void)
{
  PIEZO_TOGGLE;

  CCR0 = TimerPeriod;
  CCR1 = (CCR0 >> 1);
}

/***************************************************************************
*
*   (c) 2008 christoph(at)roboterclub-freiburg.de   // Attiny13
*   (c) 2011 christoph(at)roboterclub-freiburg.de   // MSP430G2231
*
***************************************************************************
*   This program is free software; you can redistribute it and/or modify  *
*   it under the terms of the GNU General Public License as published by  *
*   the Free Software Foundation version 2 of the License,                *
*   If you extend the program please maintain the list of authors.        *
*   If you want to use this software for commercial purposes and you      *
*   don't want to make it open source, please contact the authors for     *
*   licensing.                                                            *
***************************************************************************/
Attachments
Solarbird2.png
Solarbird2.png (210.35 KiB) Viewed 3228 times
chris
 
Posts: 260
Joined: Sun May 25, 2008 7:21 am

Re: solar bird

Postby chris on Wed Aug 15, 2012 2:37 pm

To make the solar bird more sensible to changes in its surroundings, a LED as light sensor can be used.

See the following program for details:
Attachments
SchaltplanSolarvogelMitLEDalsSensor.jpg
SchaltplanSolarvogelMitLEDalsSensor.jpg (52.35 KiB) Viewed 1661 times
SolarBird_withLedAsLightSensor.jpg
SolarBird_withLedAsLightSensor.jpg (28.31 KiB) Viewed 1755 times
SolarBird_with_LED_as_Lightsensor.zip
(19.7 KiB) Downloaded 326 times
Last edited by chris on Sun Aug 26, 2012 1:32 pm, edited 1 time in total.
chris
 
Posts: 260
Joined: Sun May 25, 2008 7:21 am

Re: solar bird

Postby chris on Wed Aug 22, 2012 7:14 pm

Solarvogel 2

The sound of the "SolarVogel 2" was inspired by one of Uwe's analog solar birds.
I recorded the sound of the analog bird and tried to reproduce it digitaly.
Attachments
SolarVogel2.zip
(7.15 KiB) Downloaded 347 times
chris
 
Posts: 260
Joined: Sun May 25, 2008 7:21 am


Return to sound

Who is online

Users browsing this forum: No registered users and 1 guest