Showing posts with label kula6. Show all posts
Showing posts with label kula6. Show all posts

Tuesday, September 22, 2015

Kula6: Schematic mistake

From the beginning of this project I had a mistake in my schematic that I was too embarrassed to recognize. My AVR ADCs were not working!!! I originally thought that I had somehow broken my processor, but turns out that I was wrong. If you see my schematic in this post you will notice that the AREF is connected to ground... wrong!!! it needs to be connected to VCC (or whichever is your reference for the analog signals). Here is a picture of how the connection should be:

 
I actually added a 100nF capacitor to ground also, which is not pictured in the schematic.

I was only planning on using the ADC for debug purposes, don't have much plans on using it on the final result, but it was frustrating that I could not get it to work.

And here is the code to read from the ADC connected to ADC0 in pin40:

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

void adc_init()
{
 // Select Vref=AVcc
 ADMUX |= (1<<REFS0);
 //set prescaller to 128 and enable ADC
 ADCSRA |= (1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0)|(1<<ADEN);
}


uint16_t adc_read(uint8_t ADCchannel)
{
 //select ADC channel with safety mask
 ADMUX = (ADMUX & 0xF0) | (ADCchannel & 0x0F);
 //single conversion mode
 ADCSRA |= (1<<ADSC);
 // wait until ADC conversion is complete
 while( ADCSRA & (1<<ADSC) );
 return ADC;
}

int main(void)
{
    adc_init();

    DDRC |= (1<<0);     //Set PortC Pin0 as an output
    PORTC |= (1<<0);        //Set PortC Pin0 high to turn on LED

    _delay_ms(500);
    PORTC ^= (1<<0);

    while(1) {
        uint16_t adc_result0 = adc_read(0);      // read adc value at PA0

        if(adc_result0>512) {
            PORTC |= (1<<0);
        }
        else {
            PORTC &= ~(1<<0);
        }

        _delay_ms(500);
    }

    return 0;
}

Sunday, August 30, 2015

Kula6: Midi IO

I have extended my platform to include midi IO, a button and a potentiometer. Here is the schematic of my platform as it is now:


And this is how the board looks:



The code it is simple, just takes Midi input, buffers it and sends it to the output. The purpose of the code was just to test that the hardware was OK.

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


unsigned char data[256];
int readPtr = 0;
int writePtr = 0;
int elements = 0;

#define BAUDRATE 31250
#define UBRR 5

void uart_init(int baudrate)
{
  // calculate division factor for requested baud rate, and set it
unsigned short bauddiv = ((F_CPU+(baudrate*8L))/(baudrate*16L)-1);
UBRRL = bauddiv;
#ifdef UBRRH
UBRRH |= bauddiv>>8;
#endif

    UCSRB = ((1<<RXEN) | (1<<TXEN) | (1<<RXCIE));   // Enable Receiver, Transmitter, Receive Interrupt
    UCSRC = ((1<<URSEL) | (1<<UCSZ1) | (1<<UCSZ0));     // 8N1 data frame
}

void uart_putc(unsigned char c)
{
    // wait until UDR ready
    while(!(UCSRA & (1 << UDRE)));
    UDR = c;    // send character
}

ISR(USART_RXC_vect)
{
    unsigned char c = UDR;

    data[writePtr] = c;
    writePtr++;
    elements++;
    if(writePtr == 256){
        writePtr = 0;
    }
}

int main(void)
{
    //Setup the clock
    cli();            //Disable global interrupts
    uart_init(BAUDRATE);
    sei();            //Enable global interrupts

    while(1){
        if(elements > 0){
            uart_putc(data[readPtr]);
            readPtr++;
            elements--;
            if(readPtr>=256){
                readPtr = 0;
            }
        }
        else {
            _delay_ms(10);
        }
    }
    return 0;
}

Thursday, June 11, 2015

My new project: Kula6

So I have started a new project... as usual for a procrastinator like me without finishing the previous one (cloudClock).

I checked my suitcase full of components to find that there were plenty of parts which I had bought and never used. I had Atmega32, DACs, PT2399 digital delay chip, ssm2164 VCA chip... so I had to do something with all that, what? definately something noisy!!!

So far my thought is doing a 6 voiced paraphonic synth with square wave oscillators and frequency dividers to get an organ type sound but with a cool 24dB/oct VCF to give it a cool synth sound. Well, that is the idea, we will see what I come up with, experimentation is the key this time. The name: Kula6, why? why not... 

Anyway, so I started with the power supply: a bipolar power supply with +/- 12V and 5V outputs and the basic circuitry for the Atmega32. I added an LED on one of the Atmega outputs for testing the usual blinky LED example. Schematic here:


And the code for the blinky LED, from hackday:

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

int main(void)
{

  //Setup the clock
  cli();            //Disable global interrupts
  TCCR1B |= 1<<CS11 | 1<<CS10;  //Divide by 64
  OCR1A = 15624;        //Count 15624 cycles for 1 second interrupt
  TCCR1B |= 1<<WGM12;     //Put Timer/Counter1 in CTC mode
  TIMSK |= 1<<OCIE1A;        //enable timer compare interrupt
  sei();            //Enable global interrupts

  //Setup the I/O for the LED

  DDRC |= (1<<0);     //Set PortC Pin0 as an output
  PORTC |= (1<<0);        //Set PortC Pin0 high to turn on LED

  while(1) { }          //Loop forever, interrupts do the rest
}

ISR(TIMER1_COMPA_vect)      //Interrupt Service Routine
{
  PORTC ^= (1<<0);        //Use xor to toggle the LED
}

And this is how my prototype board looks like: