Monday, 14 October 2019

Breadboarding/testing dc inverter


Nice smooth startup


Breadboarding/testing dc inverter with 5532 op amp and a simple Frequency Generator with arduino ( with passive LP and HP before op-amp) .

And with this last stage, i think i got a nice buffered line-level output for the Effects chain/dubsiren design.
It boiled down to the choice of either TI LMC7660, the Microchip TC1044 or this one. As it is audio and op-amps i think the compromise was the 1054, which can deliver up to 100mA, tuned slightly faster to reduce too much noise passing to the audio ( i will regulate both rails anyway from a higher voltage dc source like a 12 Volts average wall adapter).
Saves me messing about with AC centre tapped transformers.
And definitely did not want to rely on capacitive coupling alone, as not safe enough . 100 ma should allow me up to two 5532's for stereo in and stereo out buffers.

555 example circuit

For much simpler needs , a 555 can be useful as dc inverter , but not necessarily with audio beyond some guitar pedals designs maybe. 50mA unregulated, maybe 20 mA regulated. And it is load susceptible...

Filter used with arduino PWM-dac 
low pass we can calculate : 470 ohms resistor and i used 220nF .1/ (2pi*R*C) = 1539.2160840608833246507133788444 Hz cut off freq
Same for high pass :1K resistor and1uF capacitor 1/(2 pi *1000*0.000001) = 159.154943092

Arduino PWM out( @15625 Sampling) producing a 30 hz 
out through filter ... mad distortion an phase issues
"But you could low pass before the op-amp and couple it with HP
 after the buffer to improve the situation" . Yes i could... 
but do i want to in this case ? Maybe in another.
And here is why : It peaks at 1.7v !! A well worth compromise in a design
with an atmega 328 or similar



Pic from
https://www.electronicshub.org/passive-low-pass-rc-filters/

Friday, 23 August 2019

Update

New boards arrived for next dub siren/delay and EQ/Reverb combos
Also got me a new T4 @600mhz . Paul, @ pjrc done it again...




Saturday, 6 July 2019

Testing du'B Siren



Clicking one of the buttons in the the applet seems to work for most browsers
Use the app surface like a pad ( mouse or touchscreen)

Friday, 20 July 2018

LCD PCD8544

After bitbanging a quick library, and some head scratching, i seemed to have solved all my problems for now...



Thursday, 11 June 2015

UECIDE: The Universal Embedded Computing IDE



If you haven't had the chance to check the UECIDE (The Universal Embedded Computing IDE), you should give it a thought. Arduino, AVR, chipKIT, Pinguino and many more are compatible out of the box,
chipKIT boards seem to have fully deprecated the plib.h in the included compiler tools, so beware if you are using it !

Monday, 1 June 2015

Dub Siren For The Keyboard PLayer ( Code )

For the last post DUB SIREN FOR THE LIVE KEYBOARD PLAYER, all you need is an Arduino Midi Shield (  ( you should find a local distributor for all these) , an Arduino Uno, R3 preferably, and MIDI library ( I am using the Arduino_MIDI_Library_v4.2) along with this code. NO SOLDERING DONE !

#include <MIDI.h>
//
MIDI_CREATE_DEFAULT_INSTANCE();
#define PBMAX 8191
// defines for MIDI Shield components only
#define POT  0
#define POT2  1

#define BUTTON1  2
#define BUTTON2  3
#define BUTTON3  4

#define LED  7
#define LED2  6
//
#define SINSAMPLES 256
int sineData [SINSAMPLES];
bool ledOn = false;
bool ledOn2 = false;
unsigned int inc = 0;
uint16_t noteIn = 0;
uint16_t lastnote = 0;
char off = 0;
char lastplay = 0;

//char drv = 0; // digital read variable

void setup()
{
  sine();
  pinMode(LED, OUTPUT);
  pinMode(LED2, OUTPUT);
  pinMode(POT, INPUT);
  pinMode(POT2, INPUT);
  pinMode(BUTTON1, INPUT);
  // defines for MIDI Shield components only
  digitalWrite(LED2, HIGH);
  digitalWrite(LED, HIGH);
  digitalWrite(BUTTON1, HIGH);
  //
  MIDI.begin();          // Launch MIDI
}
void loop()
{ uint16_t average = noteIn;

  uint16_t anIn = analogRead(POT);
  char play = !(digitalRead(BUTTON1));
  if (lastplay != play) {
    if (play == 0)
      off = 1;
  }
  lastplay = play;
  noteIn = analogRead(POT2);

  average = (average + noteIn) >> 1;
  uint8_t note = average >> 3;

  if (play == 1) {
    if (lastnote != note) {
      MIDI.sendPitchBend(0, 1);//reset pitch bend
      delay(10);
      MIDI.sendNoteOff(lastnote, 0, 1); // Stop the note
      delay(10);
      MIDI.sendNoteOn(note, 127, 1); // Send a Note (pitch , velo 127 on channel 1)
      lastnote = note;
    }
    else {
      lastnote = note;
    }
    int smpl = sineData[inc];
    int var = (smpl - PBMAX); // this calculation can be avoided
    MIDI.sendPitchBend(var, 1);
    delay(10);
    ledOn = !ledOn;
    digitalWrite(LED, ledOn);

    inc++;
    inc += (anIn >> 4);
    if (inc >= SINSAMPLES) {
      inc -= SINSAMPLES;
      ledOn2 = !ledOn2;
      digitalWrite(LED2, ledOn2);
    }
  }
  if (play == 0) {
    if (off == 1) {
      MIDI.sendPitchBend(0, 1);//reset pitch bend
      delay(10);
      MIDI.sendNoteOff(lastnote, 0, 1); // Stop the note
      inc = 0;
      lastnote = 0;
      digitalWrite(LED2, HIGH);
      digitalWrite(LED, HIGH);
      off = 0;
    }
  }
}
void sine () {
  int i;
  int b;
  for (i = 0; i < SINSAMPLES; i++) {
    b = PBMAX * sin((2 * PI / SINSAMPLES) * i);
    b += PBMAX;
    sineData [i] = b;
  }
}

Sunday, 31 May 2015

Midi Dub Siren for the Live Keyboard Player

After seeing my bredrin David Daddy-u Mountjoy use of effects live with Dubheart  band, i thought of making this dubsiren for the Live keyboard player ( Turns any midi keyboard into a dubsiren, leds for siren on and for period of oscillation, note selector rotary knob and speed rk .
Proof of concept only.


 

YetAnotherPWM.c with the Pic32MX250F128B


During one of my tests, i was scratching my head for ages about why the PWM signal wasnt coming out on one of the remappable pins PPS. Went through examples, family datasheet, etc...
 Only to come to the conclusion that it would never work without disabling the JTAG ports in the configuration bits.

anotherpwm.c
YetAnotherpwm.X\anotherpwm.c
 1 /* 
 2  * File:   YetAnotherpwm.c
 3  * Author: Ras B.
 4  *
 5  * Created on 26 May 2015, 19:20
 6  */
 7 
 8 #include <plib.h>
 9 #include <p32xxxx.h>
10 
11 #pragma config   JTAGEN    = OFF // // disable the JTAG port  DDPCONbits.JTAGEN = 0;
12 #pragma config   FNOSC     = FRCPLL
13 #pragma config   FPLLIDIV  = DIV_2
14 #pragma config   FPLLMUL   = MUL_20
15 #pragma config   FPLLODIV  = DIV_2
16 #pragma config   FPBDIV    = DIV_1
17 #pragma config   POSCMOD   = OFF
18 #pragma config   FWDTEN    = OFF
19 //
20 #define GetSystemClock()        (40000000ul)
21 #define GetPeripheralClock()    (GetSystemClock()/(1<<OSCCONbits.PBDIV))// #define GetPeripheralClock()        (GetSystemClock()/(1<<OSCCONbits.PBDIV))
22 #define PWM_FREQ                33250
23 
24 volatile unsigned int incCount = 0; /*
25  * 
26  */
27 
28 void initAudio(void) {
29     // configures peripherals for Audio playback  
30     // Activate the PWM module
31     // OC1 in PWM mode, TMR2 based
32     OpenOC1(OC_ON | OC_TIMER2_SRC | OC_PWM_FAULT_PIN_DISABLE, 0, 0);
33     // timebase   
34     // enable TMR2, prescale 1:1, internal clock, period  
35     OpenTimer2(T2_ON | T2_PS_1_1 | T2_SOURCE_INT, 0);
36     mT2SetIntPriority(4);
37     // set TMR2 interrupt priority     
38 } // initAudio
39 
40 void startAudio(int bitrate) { // begins the audio playback
41     //  set the period for the given bitrate
42     PR2 = GetPeripheralClock() / bitrate - 1; //fpb
43     //  enable the interrupt state machine
44     mT2ClearIntFlag();
45     // clear interrupt flag   
46     mT2IntEnable(1);
47     // enable TMR2 interrupt      
48 } // startAudio
49 
50 void haltAudio(void) {
51     // stops playback state machine
52     mT2IntEnable(0);
53 } // halt audio
54 
55 main() {
56     SYSTEMConfig(GetPeripheralClock(), SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE);
57     INTEnableSystemMultiVectoredInt();
58     //
59     TRISBbits.TRISB7 = 0; //Set port as output
60     RPB7Rbits.RPB7R = 0x0005;
61     mPORTAClearBits(BIT_0); //Clear bits to ensure light is off.
62     mPORTASetPinsDigitalOut(BIT_0); //Set port as output
63     //mPORTAClearBits(BIT_0); //Clear bits to ensure light is off.
64     // Set OC1 to pin RB7 with peripheral pin select
65     RPB7Rbits.RPB7R = 0x0005;
66     initAudio();
67     OC1RS = (PR2 + 1) * ((float) 50 / 100); // pwm duty cycle can be updated here on in interrupt
68     startAudio (PWM_FREQ);
69     //timer init
70     //mT2ClearIntFlag();
71     // clear interrupt flag
72     //mT2IntEnable(1);
73     //
74     while (1) {
75         if (incCount >= (PWM_FREQ/2)) {
76             incCount = 0;
77             mPORTAToggleBits(BIT_0);
78         }
79     }//while 1
80 }//main
81 
82 void __ISR(_TIMER_2_VECTOR, ipl4) T2Interrupt(void) {
83     // 
84     incCount++;
85     // 1. load the new samples for the next cycle  
86     OC1RS = (PR2 + 1) * ((float) 50 / 100);
87     // 2. clear interrupt flag and exit
88     mT2ClearIntFlag();
89 } // T2Interrupt  
90 

Thursday, 28 May 2015

PIC32 Config Bits for 40 mHz with internal Fast RC oscillator





BlinkLED.c
ConfigBitsBlinkLED.c
/*********************************************************************
 *
 *              CONFIG BITS W/ BLINKING LED example
 * The PIC32MC250F128x is a nice little chip that boosts up to 50MHz. 
 * For applications where timing can be more lax, the use of the internal 
 * Fast RC oscillator is a good option to minimize component count, specially 
 * if you want simpler designs.
 * So, here are the config bits to have it running at 40 MHz with internal 
 * FRC oscillator .
 * The internal Fast RC Oscillator frequency is 8MHz and configured to be used 
 * with PLL; FRC(8MHz)/ FPLLIDIV (2 ) *FPLLMUL (20) /FPLLODIV (2) = 40MHz 
 * Frequency for the peripheral bus clock is left at same as the System Clock 
 * ( TPB=System Clock/PBDIV), as the divisor used is 1 (PBDIV=1)= 40MHz.
 * Also , FWDTEN = OFF // Watchdog Timer Enable OFF, and #pragma config JTAGEN = OFF 
 * // JTAG Enable OFF should be considered for use of the ports assigned to the
 *  JTAG port ( PORTB pins in this case-see datasheet for more info)
 * 
 * 
 *
 *********************************************************************
 * FileName:        ConfigBitsWLedBlink.c
 *
 * Processor:       PIC32MX250F128B
 * Dev Board:       Microstick II
 * Complier:        MPLAB C32 v2.01 or higher
 *                  MPLAB IDE v8.73 or higher
 *
 * Software License Agreement
 *
 * THIS SOFTWARE IS PROVIDED IN ANAS IS” CONDITION. NO WARRANTIES,
 * WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED
 * TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
 * PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT,
 * IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR
 * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
 *
 *
 * Author       Date            Comment
 *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 *  RB        28/5/2015         Led should blink on and off.
 * 
 ********************************************************************/
#include < xc.h > // Blog code Bug : Shorten spaces to match <xc.h>
#include < plib.h > // Shorten spaces to match <plib.h> 
#include < p32xxxx.h >  // Shorten spaces to match <p32xxxx.h>
//#pragma config FPLLMUL = MUL_20, FPLLIDIV = DIV_2, FPLLODIV = DIV_2, FWDTEN = OFF
//#pragma config POSCMOD = OFF, FNOSC = FRCPLL, FPBDIV = DIV_1
#pragma config   JTAGEN    = OFF    // JTAG Enable OFF
#pragma config   FNOSC     = FRCPLL // Fast RC w PLL 8mHz internal rc Osc
#pragma config   FPLLIDIV  = DIV_2  // PLL in 8mHz/2 = 4mHz
#pragma config   FPLLMUL   = MUL_20 // PLL mul 4mHz * 20 = 80mHz 24??
#pragma config   FPLLODIV  = DIV_2  // PLL Out 8mHz/2= 40 mHz system frequency osc
#pragma config   FPBDIV    = DIV_1  // Peripheral Bus Divisor
#pragma config   FCKSM     = CSECME // Clock Switch Enable, FSCM Enabled
#pragma config   POSCMOD   = OFF    // Primary osc disabled
#pragma config   IESO      = OFF    // Internal/external switch over
#pragma config   OSCIOFNC  = OFF    // CLKO Output Signal Active on the OSCO Pin
#pragma config   FWDTEN    = OFF    // Watchdog Timer Enable:
//
#define GetSystemClock()       (40000000ul)
#define GetPeripheralClock()    (GetSystemClock()/(1<<OSCCONbits.PBDIV))// 

main() {
    // Configure performance settings without changing PBDIV
    SYSTEMConfig(GetSystemClock(), SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE); 
    //Port Config
    mPORTAClearBits(BIT_0); //PORTA Bit 0 Clear bits to ensure light is off.
    mPORTASetPinsDigitalOut(BIT_0); //Set port RA0 as output
    // Variables
    int i;
    int j;

    while (1) { //main loop

        j = 100000;

        while (j--) { .
            mPORTAToggleBits(BIT_0); //Toggle light status. (Can be viewed in LATA SFR)

            i = j; //Time to wait in between toggle.
            while (i--) {
            } //Kill time.

            //j = j - 5000;     //Increase constant to increas blinking speed faster.
        } // while j--
    } // Main loop
} // Main


-->

Thursday, 21 May 2015

Monday, 4 May 2015

Using Cubase LE as a debugger for my code



Using Cubase LE as a debugger for my code


While testing some code for some midi controllers i thought of using Cubase to better help me debug it.
* Black is received data, blue when negative bend, red when positive and light green/blue is no update on data ( does not reset automatically until told to).
Using Pitch bend in this case.smile emoticon

* Black is received data, Blue when negative bend, Red when positive and light green/blue is no update on data ( doesnt reset automatically until told to).
Using Pitch bend in this case.


Wednesday, 29 April 2015

chipKIT DP32 Simple dub Siren Code



Sampling Rate 22.050 kHz, with 12 bit DAC MCP4725 ( breakout board)
Using button 2(Pin 17) on DP32 and Variable pot (A2).
For the signal out, the ac coupling circuit from previous post is necessary.
*Check also I2C Speed post HERE





















#include <sys/attribs.h>
#include <Wire.h>
#define MCP4725_DID 96 // define device id - see datasheet
//
#define SYS_FREQ            (40000000L)
#define PB_DIV              4
#define PRESCALE            2
#define FRQ                 22050 //21504
#define T1_TICK             (SYS_FREQ/PB_DIV/PRESCALE/FRQ)

#define WAVE_SAMPLES 256
const int buttonPin = 17; 
// variables will change:
int buttonState = 0;         // variable to read the pushbutton status
uint8_t playOn=0;            // Variable of play state/button state
volatile uint16_t a;
uint16_t b;
uint16_t d;
uint16_t e=0;
uint16_t inc;
uint8_t statedown=0;
boolean c;
boolean togg;
uint16_t sineData [WAVE_SAMPLES];
//


void setup()
{
  // Serial.begin(57600);
  initTmr();
  pinMode(A2, INPUT); //
  pinMode(13, OUTPUT); //
  //set pins to output because they are addressed in the main loop
  sine ();  
  Wire.begin() ;
}

void loop()
{
  uint16_t aIn =analogRead(A2);
  inc=aIn >>4;
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH) {  
    playOn=1;   
    // play is On    
  } 
  else{
    playOn=0;
    // play is Off

  }
  if(c !=togg){

    if(playOn==1){

      a = a++  ;
      a+= (inc+(e >>4));
      if(a>=WAVE_SAMPLES){
        a-=WAVE_SAMPLES;
        // ramp up or down variables
        if (statedown==0){
          e++;
          if(e>=1023){
            statedown=1;
            e--;
          }
        }
        else{
          e--;
          if (e==0){
            statedown=0;
            e++;
          }
        }
      }
      //
      Wire.beginTransmission(MCP4725_DID); //device adress
      Wire.send(64);                     // cmd to update the DAC
      Wire.send(sineData[a] >> 4);        // the 8 most significant bits...
      Wire.send((sineData[a] & 15) << 4); /* the 4 least significant bis...*/
      Wire.endTransmission();
      /*
       */
    } 
  }//
  c=togg;
}

// call interrupt handling vector
extern "C" {

  void __ISR(16, ipl6) int1Handler(void) 
  {
    togg= !togg;
    //
    //
    IFS0CLR = 0x80000;// Clear the T4 interrupt flag Bit 19
    //
  }
}

void initTmr(){
  // 
  T4CON=0x0; //Stop timer and clear registers
  T4CONSET = 0x0010; // set prescalar 1:2 ox60 to experiment
  TMR4 = 0x0; //Clear Timer 4 register
  PR4 = T1_TICK ; //0x17; // set timer to 23 
  IFS0CLR = 0x80000;// Clear the T4 interrupt flag Bit 19
  IPC4SET = 0x00000016;// Interrupt priority 5, 2
  IEC0SET = 0x80000;// Enable T4 interrupt Bit 19
  T4CONSET = 0x8000;// Enable Timer4  
}
void sine (){
  uint16_t i;
  for(i=0;i<WAVE_SAMPLES;i++){
    b = 2047*sin((2*PI/WAVE_SAMPLES)*i);
    b+=2047;
    sineData [i]=b;
  }
}


ChipKIT DP32 I2C Bus Speed with a MCP4725 DAC

Both arduino and MPIDE seem to have the I2C bus speed set to 100 kHz by default. So, here it is how to change it to 400kHz.
Inside the MPIDE folder, go to hardware\pic32\libraries\Wire\utility.
Inside file twi.h Find the string #define TWI_FREQ 100000 and change it to:  #defineTWI_FREQ 400000.
In my simple test i went from a 20Hz sinewave to a 72Hz just by effecting this change to the bus speed.
On the DP32 Board, SDA is assigned to Pin RB9 and SCL to Pin RB8.





Sunday, 26 April 2015

Atmega 328/Uno simple Dub synth

R2R DAC -view picture in the end of article. Usa same principle to build an 8 Bit R2R DAC from D0 to D7


Some intial test sounds out of a Uno mini Dub synth. The file was  recorded , unfiltered ( 0 to 5V) and lined out of a guitar amp in clean mode. - Some noise was introduced by the guitar amd as well.
Next step of project is to AC couple signal also with a suitable RC filter, decoupling capacitors and prepare the rest of line out for use with sound gear.
The limitations of the ATMega328 are big compared to the DUE for this kind of project, but good enough to get some interesting sounds, plus it can also double as a dub siren . Sr @ 16kHz-8Bit Dac

You can download /preview  it in mp3 here


a 6 bit R2R Dac