Go Down

Topic: Auduino v5 on uno only pot 4 works (Read 2877 times) previous topic - next topic

simonlucas

Feb 20, 2012, 10:45 am Last Edit: Feb 20, 2012, 11:04 am by simonlucas Reason: 1
As a newbie, not sure where to post this:

PROBLEM:
Using Auduino v5 code. Using digital output 13. Only pot in analogue 4 works. I can change the tone but nothing else has any affect.

(NB. Early on I switched from digital output 3 to 13, as 3 was noisy and with 13 I get a pure tone. No idea why this is as the instructions do not mention the uno board but say use digital 3 or digital 11 if using ATmega8. I get no tone using 11. Interestingly some pots in the 0-3 range had an almost inaudible effect when using output 3)

TESTS:
I tested a small 1w 8ohm speaker on the uno and can get a tone using Tone() libs.

With Auduino v5 -
I have put in fixed values instead of the analogue reads apart from No.4 to isolate the problem. This has no effect.

I have tested all 5 pots and have seen that all give 01-1023 in the serial monitor.

QUESTION:
Does this Auduino v5 code project not work with the uno? Any ideas, please?

thank-you.

dhunt

Not much to work with in your post.

What's a v5? Some kind of software? A custom arduino compatible board? A shield?

Where is your code?

What are the pots? Potentiometers on analog input pins? How are they wired?

What happens when your code works?

What happens when it doesn't work?

simonlucas

#2
Feb 20, 2012, 11:48 am Last Edit: Feb 20, 2012, 11:53 am by simonlucas Reason: 1

Not much to work with in your post.

What's a v5? Some kind of software? A custom arduino compatible board? A shield?

Where is your code?

What are the pots? Potentiometers on analog input pins? How are they wired?

What happens when your code works?

What happens when it doesn't work?


Sorry, i thought auduino was better known. The auduino is a Tinkerit 'featured' project that builds a granular additive synth. I'm using v5 (v for version) of audiuno. All your questions are answered if you look at the code and the circuit diagram. Yes pots is short for potentiometers - please see the wiring diagram on the page and you'll understand:

http://code.google.com/p/tinkerit/wiki/Auduino


With regards the last two questions. I think you'll see that I have covered this once you familiarise yourself with the auduino project

DVDdoug

Quote
Early on I switched from digital output 3 to 13
Pin 3 supports PWM, pin 13 does not.  Maybe the noise is "normal"?   Did you listen to the sample

From the Hardware Page:
Quote
...Digital I/O Pins 14 (of which 6 provide PWM output)

...PWM: 3, 5, 6, 9, 10, and 11. Provide 8-bit PWM output with the analogWrite() function.


Quote
I tested a small 1w 8ohm speaker on the uno and can get a tone using Tone() libs.
FIY - You shouldn't connect an 8-Ohm load directly to the Arduino.  It will draw too much current and may damage the chip. (5V/8 Ohms = 625mA.  The output pins are rated for 40mA.)

simonlucas

#4
Feb 22, 2012, 03:37 pm Last Edit: Feb 22, 2012, 06:38 pm by simonlucas Reason: 1

Quote
Early on I switched from digital output 3 to 13
Pin 3 supports PWM, pin 13 does not.  Maybe the noise is "normal"?   Did you listen to the sample

From the Hardware Page:
Quote
...Digital I/O Pins 14 (of which 6 provide PWM output)

...PWM: 3, 5, 6, 9, 10, and 11. Provide 8-bit PWM output with the analogWrite() function.


Quote
I tested a small 1w 8ohm speaker on the uno and can get a tone using Tone() libs.
FIY - You shouldn't connect an 8-Ohm load directly to the Arduino.  It will draw too much current and may damage the chip. (5V/8 Ohms = 625mA.  The output pins are rated for 40mA.)


DVDdoug, thanks for your input. Much appreciated.

Point 1. I realised that what is coming from pin 13 is the LED signal that is just designed to show visual feedback. So that was not correct.

I searched the code and saw that 328 chips are set to use pin3 . And then realised that the uno is also 328. That made me feel confident that I should use pin 3. Pin 3 is as you say, one of the 6 pins that supports PWM . (I'm new to this whole concept of PWM).

Yes, the noisy signal on pin 3 may be 'normal' or noisy because of the problem that is stopping the pots all the other from working. I have heard this thing playing in youtube clips and it sounds fantastic, normally.

Point 2
The people who wrote the code do not use analogWrite. They write values directly to a register address in the chip. In an article, I found the register address that people normally use for this purpose and it matches the one in the code. The article was not written for the uno, so I don;t know if we can verify that this is correct.

Point 3. I read that I had to use a resistor in series. I didn't know exactly why but I did. Thanks for explaining why.  I'm using a 100 ohm resistor . Is that OK?
The way to connect the speaker was explained here:
http://arduino.cc/en/Tutorial/tone


I hope that I'm not doing something simply wrong but I have run as many checks as I know how. Also when I hard-wire some code values (between 0 and 1023) into where it expects analogue in value, it still does not work.

I still wonder if anyone ever got this running with a Uno. Is the Uno different in any significant to the Arduino's before - and when that auduino v 5 code was written?




DuaneB

Hi,
   I also built an Auduino V5 on an UNO and only one pot had any effect. I built it very quickly just to try and so I was not surprised when it didn't work. I also hardcoded values in place of the analogReads and these did not have any effect - the same result as you observed.

   I will have another look at it now that I know it was not just down to my lack of attention while building.

   Duane B

rcarduino.blogspot.com
Read this
http://rcarduino.blogspot.com/2012/04/servo-problems-with-arduino-part-1.html
then watch this
http://rcarduino.blogspot.com/2012/04/servo-problems-part-2-demonstration.html

Rcarduino.blogspot.com

DuaneB

#6
Feb 29, 2012, 08:47 am Last Edit: Feb 29, 2012, 08:51 am by DuaneB Reason: 1
Hi,
   I have had a quick scan through the code and while I do not have an Arduino to test on at the moment, one thing you can try is adding the keyword volatile to the variable declarations -

i.e change

uint16_t syncPhaseAcc;

to

volatile uint16_t syncPhaseAcc;

and repeat this for all of the variables, it might not be needed for all but I dont have the time to check this at the moment.

Can you try it out and let me know how you get on

Duane B.

rcarduino.blogspot.com
Read this
http://rcarduino.blogspot.com/2012/04/servo-problems-with-arduino-part-1.html
then watch this
http://rcarduino.blogspot.com/2012/04/servo-problems-part-2-demonstration.html

Rcarduino.blogspot.com

DuaneB

Hi,
   I can't spare the time or hardware to test this tonight, but I have attached code updated with the volatile keyword.

This may not fix the issue, but it is a reasonable possibility that newer versions of the compiler would optimize the variables to fixed values such that changes to the values in loop would not be picked up in the interrupt routine. The volatile keyword should tell the compiler not to try to optimize the variables inside the interrupt routine even though it can't see anything that would alter their values.

If anyone can test this with a UNO and Arduino 1.0 I would be grateful, if it works I will have another look through and see which of the variables can be left and which should volatile.

Code: [Select]
// Auduino, the Lo-Fi granular synthesiser
//
// by Peter Knight, Tinker.it http://tinker.it
//
// Help:      http://code.google.com/p/tinkerit/wiki/Auduino
// More help: http://groups.google.com/group/auduino
//
// Analog in 0: Grain 1 pitch
// Analog in 1: Grain 2 decay
// Analog in 2: Grain 1 decay
// Analog in 3: Grain 2 pitch
// Analog in 4: Grain repetition frequency
//
// Digital 3: Audio out (Digital 11 on ATmega8)
//
// Changelog:
// 19 Nov 2008: Added support for ATmega8 boards
// 21 Mar 2009: Added support for ATmega328 boards
// 7 Apr 2009: Fixed interrupt vector for ATmega328 boards
// 8 Apr 2009: Added support for ATmega1280 boards (Arduino Mega)

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

volatile uint16_t syncPhaseAcc;
volatile uint16_t syncPhaseInc;
volatile uint16_t grainPhaseAcc;
volatile uint16_t grainPhaseInc;
volatile uint16_t grainAmp;
volatile uint8_t grainDecay;
volatile uint16_t grain2PhaseAcc;
volatile uint16_t grain2PhaseInc;
volatile uint16_t grain2Amp;
volatile uint8_t grain2Decay;

// Map Analogue channels
#define SYNC_CONTROL         (4)
#define GRAIN_FREQ_CONTROL   (0)
#define GRAIN_DECAY_CONTROL  (2)
#define GRAIN2_FREQ_CONTROL  (3)
#define GRAIN2_DECAY_CONTROL (1)


// Changing these will also requires rewriting audioOn()

#if defined(__AVR_ATmega8__)
//
// On old ATmega8 boards.
//    Output is on pin 11
//
#define LED_PIN       13
#define LED_PORT      PORTB
#define LED_BIT       5
#define PWM_PIN       11
#define PWM_VALUE     OCR2
#define PWM_INTERRUPT TIMER2_OVF_vect
#elif defined(__AVR_ATmega1280__)
//
// On the Arduino Mega
//    Output is on pin 3
//
#define LED_PIN       13
#define LED_PORT      PORTB
#define LED_BIT       7
#define PWM_PIN       3
#define PWM_VALUE     OCR3C
#define PWM_INTERRUPT TIMER3_OVF_vect
#else
//
// For modern ATmega168 and ATmega328 boards
//    Output is on pin 3
//
#define PWM_PIN       3
#define PWM_VALUE     OCR2B
#define LED_PIN       13
#define LED_PORT      PORTB
#define LED_BIT       5
#define PWM_INTERRUPT TIMER2_OVF_vect
#endif

// Smooth logarithmic mapping
//
uint16_t antilogTable[] = {
  64830,64132,63441,62757,62081,61413,60751,60097,59449,58809,58176,57549,56929,56316,55709,55109,
  54515,53928,53347,52773,52204,51642,51085,50535,49991,49452,48920,48393,47871,47356,46846,46341,
  45842,45348,44859,44376,43898,43425,42958,42495,42037,41584,41136,40693,40255,39821,39392,38968,
  38548,38133,37722,37316,36914,36516,36123,35734,35349,34968,34591,34219,33850,33486,33125,32768
};
uint16_t mapPhaseInc(uint16_t input) {
  return (antilogTable[input & 0x3f]) >> (input >> 6);
}

// Stepped chromatic mapping
//
uint16_t midiTable[] = {
  17,18,19,20,22,23,24,26,27,29,31,32,34,36,38,41,43,46,48,51,54,58,61,65,69,73,
  77,82,86,92,97,103,109,115,122,129,137,145,154,163,173,183,194,206,218,231,
  244,259,274,291,308,326,346,366,388,411,435,461,489,518,549,581,616,652,691,
  732,776,822,871,923,978,1036,1097,1163,1232,1305,1383,1465,1552,1644,1742,
  1845,1955,2071,2195,2325,2463,2610,2765,2930,3104,3288,3484,3691,3910,4143,
  4389,4650,4927,5220,5530,5859,6207,6577,6968,7382,7821,8286,8779,9301,9854,
  10440,11060,11718,12415,13153,13935,14764,15642,16572,17557,18601,19708,20879,
  22121,23436,24830,26306
};
uint16_t mapMidi(uint16_t input) {
  return (midiTable[(1023-input) >> 3]);
}

// Stepped Pentatonic mapping
//
uint16_t pentatonicTable[54] = {
  0,19,22,26,29,32,38,43,51,58,65,77,86,103,115,129,154,173,206,231,259,308,346,
  411,461,518,616,691,822,923,1036,1232,1383,1644,1845,2071,2463,2765,3288,
  3691,4143,4927,5530,6577,7382,8286,9854,11060,13153,14764,16572,19708,22121,26306
};

uint16_t mapPentatonic(uint16_t input) {
  uint8_t value = (1023-input) / (1024/53);
  return (pentatonicTable[value]);
}


void audioOn() {
#if defined(__AVR_ATmega8__)
  // ATmega8 has different registers
  TCCR2 = _BV(WGM20) | _BV(COM21) | _BV(CS20);
  TIMSK = _BV(TOIE2);
#elif defined(__AVR_ATmega1280__)
  TCCR3A = _BV(COM3C1) | _BV(WGM30);
  TCCR3B = _BV(CS30);
  TIMSK3 = _BV(TOIE3);
#else
  // Set up PWM to 31.25kHz, phase accurate
  TCCR2A = _BV(COM2B1) | _BV(WGM20);
  TCCR2B = _BV(CS20);
  TIMSK2 = _BV(TOIE2);
#endif
}


void setup() {
  pinMode(PWM_PIN,OUTPUT);
  audioOn();
  pinMode(LED_PIN,OUTPUT);
}

void loop() {
  // The loop is pretty simple - it just updates the parameters for the oscillators.
  //
  // Avoid using any functions that make extensive use of interrupts, or turn interrupts off.
  // They will cause clicks and poops in the audio.
 
  // Smooth frequency mapping
  //syncPhaseInc = mapPhaseInc(analogRead(SYNC_CONTROL)) / 4;
 
  // Stepped mapping to MIDI notes: C, Db, D, Eb, E, F...
  //syncPhaseInc = mapMidi(analogRead(SYNC_CONTROL));
 
  // Stepped pentatonic mapping: D, E, G, A, B
  syncPhaseInc = mapPentatonic(analogRead(SYNC_CONTROL));

  grainPhaseInc  = mapPhaseInc(analogRead(GRAIN_FREQ_CONTROL)) / 2;
  grainDecay     = analogRead(GRAIN_DECAY_CONTROL) / 8;
  grain2PhaseInc = mapPhaseInc(analogRead(GRAIN2_FREQ_CONTROL)) / 2;
  grain2Decay    = analogRead(GRAIN2_DECAY_CONTROL) / 4;
}

SIGNAL(PWM_INTERRUPT)
{
  uint8_t value;
  uint16_t output;

  syncPhaseAcc += syncPhaseInc;
  if (syncPhaseAcc < syncPhaseInc) {
    // Time to start the next grain
    grainPhaseAcc = 0;
    grainAmp = 0x7fff;
    grain2PhaseAcc = 0;
    grain2Amp = 0x7fff;
    LED_PORT ^= 1 << LED_BIT; // Faster than using digitalWrite
  }
 
  // Increment the phase of the grain oscillators
  grainPhaseAcc += grainPhaseInc;
  grain2PhaseAcc += grain2PhaseInc;

  // Convert phase into a triangle wave
  value = (grainPhaseAcc >> 7) & 0xff;
  if (grainPhaseAcc & 0x8000) value = ~value;
  // Multiply by current grain amplitude to get sample
  output = value * (grainAmp >> 8);

  // Repeat for second grain
  value = (grain2PhaseAcc >> 7) & 0xff;
  if (grain2PhaseAcc & 0x8000) value = ~value;
  output += value * (grain2Amp >> 8);

  // Make the grain amplitudes decay by a factor every sample (exponential decay)
  grainAmp -= (grainAmp >> 8) * grainDecay;
  grain2Amp -= (grain2Amp >> 8) * grain2Decay;

  // Scale output to the available range, clipping if necessary
  output >>= 9;
  if (output > 255) output = 255;

  // Output to PWM (this is faster than using analogWrite) 
  PWM_VALUE = output;
}


Duane B

rcarduino.blogspot.com
Read this
http://rcarduino.blogspot.com/2012/04/servo-problems-with-arduino-part-1.html
then watch this
http://rcarduino.blogspot.com/2012/04/servo-problems-part-2-demonstration.html

Rcarduino.blogspot.com

simonlucas


Hi,
   I can't spare the time or hardware to test this tonight, but I have attached code updated with the volatile keyword.


Duane,

sorry - I only just saw your replies as I'd given up thinking about this project weeks ago. Thank-you for your input and I will try your suggestion asap, this week.

Regards

Simon

DuaneB

Hi,
   Glad to see you have come back to it, still busy myself, I have been to six, maybe seven countries since I replied. I really want to build an Auduino myself so hope this is the fix for it, if not I will have another look when I get home.

Duane B

rcarduino.blogspot.com
Read this
http://rcarduino.blogspot.com/2012/04/servo-problems-with-arduino-part-1.html
then watch this
http://rcarduino.blogspot.com/2012/04/servo-problems-part-2-demonstration.html

Rcarduino.blogspot.com

dxw00d

Quote
I'm using a 100 ohm resistor . Is that OK?


No. 5V/108ohms is 46mA.

Go Up