Go Down

Topic: Audino V5 in IDE 1.0 Possible Solution (Read 1 time) previous topic - next topic

DuaneB

Apr 08, 2012, 09:07 pm Last Edit: Apr 09, 2012, 07:36 am by DuaneB Reason: 1
Hi,
   For anyone trying to get the Audino project to run and finding that only pot 4 changes anything, you need to add the volatile keyword to the variable declarations. My assumption is that a new compiler optimisation in Arduino 1.0 is replacing the variables inside the ISRs with local (register based) copies which are not updated by the analogReads in the main loop.

I have left a suggestion to this effect on the Audino project page for the project owners.

I am just breadboarding the project at the moment with a mismatch of components, once I have a suitable set up to confirm the results I will post my suggestion for an Arduino 1.0 compatible version, in the meantime you can add volatile to all of the global variables as such -

Code: [Select]

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;


Note - The volatile keyword is not needed in every case however I do not have the resources to confirm which at the moment.

EDIT - for clarity.

Duane B

rcarduino.blogspot.com

robtillaart

Quote
For anyone trying to get the Audino project to run and finding that only pot 4 changes anything,


I do not understand the problem.

Why should we make all global vars volatile?
Vars need only be volatile to prevent the compiler from optimizing them with registers.
Typically used in synchronization issues between a main program and ISR's (and probably some other cases).


Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Nick Gammon

Hopefully he means: "variables which are shared between an ISR and the main code".

That is all that needs to be made volatile and it was always thus.

DuaneB

Hi,
   Are either of you using Auduino V5 with IDE 1.0 ? thats 'Auduino' not 'Arduino'

   Are either of you using Auduino with any version of the IDE ?

   If not, you can download the code from - http://code.google.com/p/tinkerit/

   You will see that there are a set of global variables that set the synth parameters in loop.

   These same global variables are used in a timer driven ISR to create the synth output.

   The code does not work correctly for me as it is presented on the site, the analogue inputs have no effect. On reading through the code it looked quite likely that the global variables are being optimized in some fashion that the copies in loop are not updating the copies in the ISR. On this basis I added volatile to the variable declarations and now all analogInputs are correctly controlling the synth parameters.

Quote

I do not understand the problem.

Why should we make all global vars volatile?
Vars need only be volatile to prevent the compiler from optimizing them with registers.
Typically used in synchronization issues between a main program and ISR's (and probably some other cases).


Indeed.

Quote

That is all that needs to be made volatile and it was always thus.


While it may have always been so, it is not so in the Audino code which is my I am suggesting this fix.


Duane B

rcarduino.blogspot.com

Nick Gammon

I would expect these variables to be needed as volatile:

Code: [Select]
syncPhaseInc
grainPhaseInc
grainDecay
grain2PhaseInc
grain2Decay


That is because they are used in both loop and the ISR.

Can you name another variable that needs to be made volatile for it to work?

You are correct that the code needs those (above), and therefore the code on the site is wrong. But that is simply because those ones are the ones that are shared between inside an ISR and outside an ISR.

DuaneB

Hi,
   From my original post -

Quote

Note - The volatile keyword is not needed in every case however I do not have the resources to confirm which at the moment.


I assume that its just these five but would like to do a quick test this evening before posting a final copy of the updated code.

Duane B

rcarduino.blogspot.com



DuaneB

This isn't what I was planning, but I have been out and accidentally bought a nice rugged clear topped enclosure. It was way too expensive but seeing the clear top I couldn't get away from the idea of combining the Audino with an LED Chaser/visualizer of some sort. The Audino only uses timer2 so that leaves me 0 and 1 for PWM, I also picked up some hex drivers and 4017's for chasers.

Duane B

rcarduino.blogspot.com

Go Up