Welcome, Guest
Username: Password: Remember me

TOPIC: Programming My First Time Manipulator Effect

Programming My First Time Manipulator Effect 4 years 1 month ago #1660

  • Ray
  • Ray's Avatar
  • OFFLINE
  • Moderator
  • Posts: 702
  • Thank you received: 152
  • Karma: 44
This simple tutorial will introduce you to program the Time Manipulator effect pedal.
Basic notions of C programming are needed to understand the code. There are great tutorials in Youtube to learn how to code basic C, but don't expect to learn it in 30 minutes.

We are going to start with a simple Delay Effect:

delay_2019-02-04.jpg




1. First of all, you need to know how all the resources are connected to the microcontroller (ATMEGA328P-PU), you can have a look at the schematic or check the image below.
Time-Manipulator-Block-Diagram.png




Pin Definitions:
The first part of the code will always be to define the pins of the microcontroller:
// Pin Definitions: 
#define DELAY1 10
#define DELAY2 9
#define SWA 3
#define SWB 14
#define SWC 2
#define SWD 4 
#define LED1_G 1 
#define LED1_R 0
#define LED2_G 5
#define LED2_R 6
#define ENC_A 16
#define ENC_B 18
#define ENC_GND 17
#define ENC_PUSH 19
#define BYPASS_DETECT 8
#define TAP_DETECT  15
Where DELAY1/2 are the PWM signals that will control the delay time on the PT2399 chips, SWA/B/C/D are the analog switches (from the CD4066), LED1/2_G/R are the leds 1 and 2 and the Green and Red lines, ENC_A/B/GND/PUSH are the encoder related lines (+ the push button which is integrated on the encoder itself), the BYPASS_DETECT will detect the True Bypass foot-switch and the TAP_DETECT will detect the TAP foot-switch.


Variables:
Then we have the variables defined, they will be later used in the code. All of them are used in the read_encoder function. The read_encoder function is also declared here:
//VARIABLES
unsigned int ENC_counter = 100; 
int ENC_aState;
int ENC_aLastState;  
int ENC_aState_selection=0;
int ENC_aLastState_selection=0;
void read_encoder(void);


Setup:
The setup part of the code will be executed only one time, we would need to define here the pins as INPUTS or OUTPUTS and the initial value for them:
void setup() 
{
//set the pins //init the values
pinMode(DELAY1, OUTPUT);    analogWrite(DELAY1, 100);
pinMode(DELAY2, OUTPUT);    analogWrite(DELAY2, 100);
pinMode(SWA, OUTPUT);       digitalWrite(SWA, LOW);
pinMode(SWB, OUTPUT);       digitalWrite(SWB, LOW);
pinMode(SWC, OUTPUT);       digitalWrite(SWC, LOW);
pinMode(SWD, OUTPUT);       digitalWrite(SWD, LOW);
pinMode(LED1_G, OUTPUT);    analogWrite(LED1_G, 0);
pinMode(LED1_R, OUTPUT);    analogWrite(LED1_R, 0);
pinMode(LED2_G, OUTPUT);    analogWrite(LED2_G, 0);
pinMode(LED2_R, OUTPUT);    analogWrite(LED2_R, 0);
pinMode(ENC_A, INPUT_PULLUP);
pinMode(ENC_B, INPUT_PULLUP);
pinMode(ENC_GND, OUTPUT);
pinMode(ENC_PUSH, INPUT_PULLUP);
pinMode(BYPASS_DETECT, INPUT_PULLUP);
pinMode(TAP_DETECT, INPUT_PULLUP);
ENC_aLastState = digitalRead(ENC_A); 
}
*NOTE: some of the INPUTS have also a PULLUP. You can learn about pull-ups and pull-downs here. Basically, pull-up inputs here will be HIGH by default.


Loop:
Right After the Setup, the main Loop is executed, this loop will run endlessly:
void loop() // the loop function runs over and over again forever
{
//detect if the effect is on or off
while((digitalRead(BYPASS_DETECT) == LOW)) 
  {
  digitalWrite(LED1_R,LOW);digitalWrite(LED2_R,LOW);digitalWrite(LED1_G,LOW);digitalWrite(LED2_G,LOW); 
  }  
read_encoder();
//update the delay value based on the encoder reading
analogWrite(DELAY1, ENC_counter);
analogWrite(DELAY2, ENC_counter);
//update the LED colors
digitalWrite(LED1_G,HIGH); digitalWrite(LED2_G,HIGH);digitalWrite(LED1_R,LOW);  digitalWrite(LED2_R,LOW);    
//set the audio relay
digitalWrite(SWA, LOW);digitalWrite(SWB, HIGH);digitalWrite(SWC, HIGH);digitalWrite(SWD, LOW);
}

Let's check instruction by instruction:
  • while((digitalRead(BYPASS_DETECT) == LOW)) 
      {
      digitalWrite(LED1_R,LOW);digitalWrite(LED2_R,LOW);digitalWrite(LED1_G,LOW);digitalWrite(LED2_G,LOW); 
      }
    If the BYPASS_DETECT footswitch is pressed, the code goes into a loop that only switch off all the LEDs, the code will be doing nothing until the footswitch goes into ON mode.
  • read_encoder();
    This funtcion will read the value of the encoder (labelled as "MASTER" with the stickers), the read_encoder function looks like this:
    void read_encoder(void)
    {
     ENC_aState = digitalRead(ENC_A); // Reads the "current" state
       if (ENC_aState != ENC_aLastState)
       {    
         if (digitalRead(ENC_B) != ENC_aState) 
              {if(ENC_counter>50)ENC_counter-=5;}
         else 
              {if(ENC_counter<230)ENC_counter+=5;}   
       } 
    ENC_aLastState = ENC_aState; // Updates the prev. state  
    }
    This function was taken from here: playground.arduino.cc/Main/RotaryEncoders it will update the ENC_counter (meaning "ENCODER counter") from 230 (maximum value) to 50 (minimum value). In increments of 5, why? because if the increment is 1 by one it takes too many turns to go from minimum to maximum. You can experiment with the increment value. The reason of 230 and 50 as max and min will be explained in the next points.
  • //update the delay value based on the encoder reading
    analogWrite(DELAY1, ENC_counter);
    analogWrite(DELAY2, ENC_counter);
  • This is a key instruction in the code, writing an analog value in the DELAY1 and DELAY2 pins will adjust the amount of delay that the PT2399 chips will use. With the 230=minimum delay and 50=maximum delay.
    In theory we can use the
analogWrite
function with values from 0 to 255 (8 bits). With the Time Manipulator pedal, its better to limit the values from 50 to 230. If we use the 0 or the 255 value, the PT2399 chips (the chips that control the delay of the signal) will be working in their limits, it will not damage the chips but the sound will break, creating distortion.
  • //update the LED colors
    digitalWrite(LED1_G,HIGH); digitalWrite(LED2_G,HIGH);digitalWrite(LED1_R,LOW);  digitalWrite(LED2_R,LOW); 
    This 4 instructions will set the LED colors. The pedal uses two bicolor LEDs, you can light each one in green, red or orange (red + green).
    This especific instructions set the two Green leds to HIGH (on), you can experiment with different colors.
  • //set the audio relay
    digitalWrite(SWA, LOW);digitalWrite(SWB, HIGH);digitalWrite(SWC, HIGH);digitalWrite(SWD, LOW);
    The pedal has 4 analog switches (SWA, SWB, SWC, SWD) with this 4 instructions you can set the audio path as you like. The one used in this code (SWA=off, SWB=on, SWC=on, SWD=off) is a

    You can see all the possible configurations of the pedal in this image:
    Time_Manipulator-Relay_Configurations-ElectroSmash_2019-01-30.png



  • And that is all!, in a code like this the typical variations you can easily try are:
    • Modify the audio relays to create different sounds. (digitalWrite(SWA/B/C/D, HIGH/LOW) operation)
    • Change the amount of delay (analogWrite(DELAY1/DELAY2, time_value) the time_value goes from 50 max delay to 230 min delay)
    • Change the encoder increment vale, so the pot will get faster/slower from minimum to maximum value. The default is 5, but you can change it by 1, 4, 10, etc... (if(ENC_counter>50)ENC_counter-=5);

    The complete Delay code is in the DELAY TOPIC.


    Next Steps?:
    Last Edit: 4 years 1 month ago by Ray.
    The administrator has disabled public write access.

    Programming My First Time Manipulator Effect 3 years 11 months ago #1769

    • fuem
    • fuem's Avatar
    • OFFLINE
    • New Member
    • Posts: 3
    • Karma: 0
    Ray , I want to ask a simple question , if i buy a preprogrammed ic from your shop,that means I dont need to do anything about hardware right ? I only need to put it right ?
    The administrator has disabled public write access.

    Programming My First Time Manipulator Effect 3 years 10 months ago #1774

    • Ray
    • Ray's Avatar
    • OFFLINE
    • Moderator
    • Posts: 702
    • Thank you received: 152
    • Karma: 44
    Ray , I want to ask a simple question , if i buy a preprogrammed ic from your shop,that means I dont need to do anything about hardware right ? I only need to put it right ?

    The preprogrammed IC that we have in the store does not need any programming or coding from the user point of view.
    It is literally "plug and play".

    PS: But If you want to do it yourself you just need to get an ATMEGAP-PU from Amazon/Mouser/Farnell/eBay and follow this www.electrosmash.com/forum/time-manipula...-manipulator?lang=en
    The administrator has disabled public write access.
    Time to create page: 0.325 seconds
    Powered by Kunena Forum
    Joomla SEF URLs by Artio