Welcome, Guest
Username: Password: Remember me

TOPIC: Software Utilities

Software Utilities 5 years 3 weeks ago #4

  • JR
  • JR's Avatar
  • OFFLINE
  • Senior Member
  • Posts: 77
  • Thank you received: 31
  • Karma: 6
I would like to share some utility programs which can be useful to configure and set-up pedalSHIELD.

adjust_trimmer.ino:

This code is useful to adjust the trimmer RV1 in order to set the gain of the first op-amp to the maximum and without saturating the ADCs.
The ADC0 reads the input signal from the guitar, if the level is too high (over 4090) the LED is turned on. The idea is to adjust the trimmer while playing guitar (open E2 for instance), if the LED is ON means that the gain is too high (in that case just turn the trimmer down a little until the LED goes off):
// Licensed under a Creative Commons Attribution 3.0 Unported License.
// www.electrosmash.com/pedalshield
// Based on rcarduino.blogspot.com previous work.
 
int in_ADC0, in_ADC1;  //variables for 2 ADCs values (ADC0, ADC1)
int POT0, POT1, POT2, in_DAC0, in_DAC1; //variables for 3 pots (ADC8, ADC9, ADC10)
int LED = 3;
int FOOTSWITCH = 7; 
int TOGGLE = 2; 
 
void setup()
{
  //ADC Configuration
  ADC->ADC_MR |= 0x80;   // DAC in free running mode.
  ADC->ADC_CR=2;         // Starts ADC conversion.
  ADC->ADC_CHER=0x1CC0;  // Enable ADC channels 0,1,8,9 and 10  
 
   //Pin Configuration
  pinMode(LED, OUTPUT);   
}
 
void loop()
{
  //Read the ADCs
  while((ADC->ADC_ISR & 0x1CC0)!=0x1CC0);// wait for ADC 0, 1, 8, 9, 10 conversion complete.
  in_ADC0=ADC->ADC_CDR[7];           // read data from ADC0
  in_ADC1=ADC->ADC_CDR[6];           // read data from ADC1  
 
  if (in_ADC0>=4090) 
   {
    digitalWrite(LED, HIGH); 
    delay(200);
   }
 
  else 
    digitalWrite(LED, LOW); 
}
}


File Attachment:

File Name: adjust_trimmer.rar
File Size: 1 KB
keep it simple
Last Edit: 5 years 1 week ago by JR.
The administrator has disabled public write access.

Software Utilities 5 years 3 weeks ago #5

  • JR
  • JR's Avatar
  • OFFLINE
  • Senior Member
  • Posts: 77
  • Thank you received: 31
  • Karma: 6
test_all.ino:

This program can test all the hardware (the three potentiometers, the footswitch, the toggle switch, ADCs and DACs)
  • pedalSHIELD works as a clean pedal, when activated the signal is read by ADCs and written by DACs
  • Potentiometer0, Potentiometer1 and Potentiometer2 act as volume controls.
  • When the effect is ON, the LED is also ON
  • When the effect is OFF, the LED can be activated/deactivated using the toggle button.
// Licensed under a Creative Commons Attribution 3.0 Unported License.
// Based on rcarduino.blogspot.com previous work.
// www.electrosmash.com/pedalshield
 
int in_ADC0, in_ADC1;  //variables for 2 ADCs values (ADC0, ADC1)
int POT0, POT1, POT2, out_DAC0, out_DAC1; //variables for 3 pots (ADC8, ADC9, ADC10)
int LED = 3;
int FOOTSWITCH = 7; 
int TOGGLE = 2; 
 
void setup()
{
  //ADC Configuration
  ADC->ADC_MR |= 0x80;   // DAC in free running mode.
  ADC->ADC_CR=2;         // Starts ADC conversion.
  ADC->ADC_CHER=0x1CC0;  // Enable ADC channels 0 and 1.  
 
  //DAC Configuration
  analogWrite(DAC0,0);  // Enables DAC0
  analogWrite(DAC1,0);  // Enables DAC0
 
  //Pin Configuration
  pinMode(LED, OUTPUT);  
  pinMode(FOOTSWITCH, INPUT);     
  pinMode(TOGGLE, INPUT);     
}
 
void loop()
{
  //Read the ADCs
  while((ADC->ADC_ISR & 0x1CC0)!=0x1CC0);// wait for ADC 0, 1, 8, 9, 10 conversion complete.
  in_ADC0=ADC->ADC_CDR[7];           // read data from ADC0
  in_ADC1=ADC->ADC_CDR[6];           // read data from ADC1  
  POT0=ADC->ADC_CDR[10];                // read data from ADC8        
  POT1=ADC->ADC_CDR[11];                // read data from ADC9   
  POT2=ADC->ADC_CDR[12];                // read data from ADC10 
 
  //Add volume feature for POT0
  out_DAC0=map(in_ADC0,0,4095,1,POT0);
  out_DAC1=map(in_ADC1,0,4095,1,POT0);
 
  //Add volume feature for POT1
  out_DAC0=map(out_DAC0,0,4095,1,POT1);
  out_DAC1=map(out_DAC1,0,4095,1,POT1);
 
  //Add volume feature for POT2
  out_DAC0=map(out_DAC0,0,4095,1,POT2);
  out_DAC1=map(out_DAC1,0,4095,1,POT2);
 
  //Write the DACs
  dacc_set_channel_selection(DACC_INTERFACE, 0);          //select DAC channel 0
  dacc_write_conversion_data(DACC_INTERFACE, out_DAC0);//write on DAC
  dacc_set_channel_selection(DACC_INTERFACE, 1);          //select DAC channel 1
  dacc_write_conversion_data(DACC_INTERFACE, out_DAC1);//write on DAC
 
  //Check the FOOTSWITCH and light the LED
    if (digitalRead(FOOTSWITCH)) digitalWrite(LED, HIGH); 
    else  digitalWrite(LED, LOW); 
 
  //Check the TOGGLE SWITCH and light the LED
    if (digitalRead(TOGGLE)) digitalWrite(LED, HIGH); 
    else  digitalWrite(LED, LOW); 
}

File Attachment:

File Name: test_all.rar
File Size: 1 KB
keep it simple
Last Edit: 5 years 1 week ago by JR.
The administrator has disabled public write access.

Software Utilities 4 years 9 months ago #86

  • alanb
  • alanb's Avatar
  • OFFLINE
  • New Member
  • Posts: 1
  • Thank you received: 3
  • Karma: 0
I finished building my pedalSHIELD earlier this week and tested it with test_all.ino. It worked fine but I wanted to see the inputs on the serial monitor so I created the following program. It moves the adc reads into an interrupt routine so I can use print's in the loop() without slowing down the adc.
// The MIT License (MIT)
//
// Copyright (c) 2014 Alan Backlund
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
 
// Based on www.electrosmash.com/pedalshield previous work.
 
int in_ADC0, in_ADC1;  //variables for 2 ADCs values (ADC0, ADC1)
long avg;
int POT0, POT1, POT2, out_DAC0, out_DAC1; //variables for 3 pots (ADC8, ADC9, ADC10)
 
const int LED = 3;
const int FOOTSWITCH = 7; 
const int TOGGLE = 2; 
const int FILTER = 2048;
 
void setup()
{
  Serial.begin(9600);
  Serial.println("PedalShield HW Test");
 
  //turn on the timer clock in the power management controller
  pmc_set_writeprotect(false);
  pmc_enable_periph_clk(ID_TC4);
 
  //we want wavesel 01 with RC 
  TC_Configure(TC1, 1, TC_CMR_WAVE | TC_CMR_WAVSEL_UP_RC | TC_CMR_TCCLKS_TIMER_CLOCK2);
  TC_SetRC(TC1, 1, 109); // sets <> 44.1 Khz interrupt rate
  TC_Start(TC1, 1);
 
  // enable timer interrupts on the timer
  TC1->TC_CHANNEL[1].TC_IER = TC_IER_CPCS;
  TC1->TC_CHANNEL[1].TC_IDR = ~TC_IER_CPCS;
 
  //Enable the interrupt in the nested vector interrupt controller 
  //TC4_IRQn where 4 is the timer number * timer channels (3) + the channel 
  //number (=(1*3)+1) for timer1 channel1 
  NVIC_EnableIRQ(TC4_IRQn);
 
  //ADC Configuration
  ADC->ADC_MR |= 0x80;   // DAC in free running mode.
  ADC->ADC_CR = 2;         // Starts ADC conversion.
  ADC->ADC_CHER = 0x1CC0;  // Enable ADC channels 0, 1, 8, 9, 10. 
 
  // enable ADC interrupts on the timer
  ADC->ADC_IER = 0x00C0;
  ADC->ADC_IDR = ~0x00C0;
 
  //Enable the interrupt in the nested vector interrupt controller 
  NVIC_EnableIRQ(ADC_IRQn); 
 
  //DAC Configuration
  analogWrite(DAC0,0);  // Enables DAC0
  analogWrite(DAC1,0);  // Enables DAC0
 
  //pedalSHIELD pin configuration
  pinMode(LED, OUTPUT);  
  pinMode(FOOTSWITCH, INPUT);     
  pinMode(TOGGLE, INPUT);  
 
  Serial.println("Begin");
}
 
void loop()
{
  //Read the ADCs
  while((ADC->ADC_ISR & 0x1C00) != 0x1C00)
    ;  // wait for ADC 8, 9, 10 conversion complete.
  POT0 = ADC->ADC_CDR[10];                 // read data from ADC8        
  POT1 = ADC->ADC_CDR[11];                 // read data from ADC9   
  POT2 = ADC->ADC_CDR[12];                 // read data from ADC10 
 
  Serial.print("p1 ");
  Serial.print(POT0);
  Serial.print(", p2 ");
  Serial.print(POT1);
  Serial.print(", p3 ");
  Serial.print(POT2);
  Serial.print(", fs ");
  Serial.print(digitalRead(FOOTSWITCH));
  Serial.print(", s3 ");
  Serial.print(digitalRead(TOGGLE));
//  Serial.print(", a0 ");
//  Serial.print(in_ADC0);
//  Serial.print(", a1 ");
//  Serial.print(in_ADC1);
  Serial.print(", level ");
  Serial.println(avg / FILTER);
 
  if (digitalRead(TOGGLE))
    digitalWrite(LED, HIGH); 
  else
    digitalWrite(LED, LOW); 
 
  delay(100);
}
 
void TC4_Handler() //Interrupt at 44.1KHz rate (every 22.6us)
{ 
  TC_GetStatus(TC1, 1); //Clear status to fire again the interrupt.
 
  //Add volume feature with POT2
  out_DAC0=map(in_ADC0,0,4095,1,POT2);
  out_DAC1=map(in_ADC1,0,4095,1,POT2);
 
  //Write the DACs
  dacc_set_channel_selection(DACC_INTERFACE, 0);       //select DAC channel 0
  dacc_write_conversion_data(DACC_INTERFACE, out_DAC0);//write on DAC
  dacc_set_channel_selection(DACC_INTERFACE, 1);       //select DAC channel 1
  dacc_write_conversion_data(DACC_INTERFACE, out_DAC1);//write on DAC
}
 
void ADC_Handler()
{
  int adcisr = ADC->ADC_ISR;
 
  //Read the ADCs
  if((adcisr & 0x0080) == 0x0080) // wait for ADC 0, 1 conversion complete.
    in_ADC0 = ADC->ADC_CDR[7];               // read data from ADC0
  if((adcisr & 0x0040) == 0x0040) // wait for ADC 0, 1 conversion complete.
    in_ADC1 = ADC->ADC_CDR[6];               // read data from ADC1  
 
  int v = abs(in_ADC0 - in_ADC1);
  avg = (avg - (avg / FILTER) + v);
}
The administrator has disabled public write access.
The following user(s) said Thank You: gamoesp, JR, estim8d
Time to create page: 0.158 seconds
Powered by Kunena Forum
Joomla SEF URLs by Artio

Our Instagram

Follow us

You can also follow us on:

facebook   google   instagram

pinterest   youtube   twitter