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);
  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) {  
    // play is On    
    // play is Off

  if(c !=togg){


      a = a++  ;
      a+= (inc+(e >>4));
        // ramp up or down variables
        if (statedown==0){
          if (e==0){
      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...*/

// 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;
    b = 2047*sin((2*PI/WAVE_SAMPLES)*i);
    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

ac coupling of a 0-5 V signal from Atmega328

Example of a signal with dc offset, and after the passive filter

Having  a 0 to 5 V signal generated digitally with a R2R 8 bit dac, i needed to remove the offset introduced . This is a simple way and also makes it to "audio friendly" .

Low pass filter and ac coupling circuit block used in one of my projects

Tuesday, 21 April 2015

The Arduino saga for the confused user, Clash Of IDE's and what not's

As confused as most users, i  will try break it down gently my perception of it all.

First, you should start by a nicely done history and time line presentation i found, by Matthew Williamson.

Arduino LLC was founded by Massimo Banzi, David Cuartielles, David Mellis, Tom Igoe and Gianluca Martino in 2009.
Considering Arduino idea started around 2005, a lot of these guys had been working togethers since.
The other party is Smart Projects, founded by Gianluca Martino in 2004, which has always been one of the major manufacturers of Arduino Boards.
A rift started ( you can check the full breakdown in the series of articles on Hackaday)  and Smart Projects changed their name to Arduino SRL in November of 2014. A new site was started ( and the Clash of IDE's started, confusing a lot of people in the process.
Warnings on some boards started to appear with version 1.6.1 that "Added warning for uncertified boards" ( apparently  some USB Vendor ID's from boards manufactured  by the "ORG" camp . And this is confusing for the average user.'s version 1.6.3 is the official version, but released a few versions with higher numbers to confuse the matter ( 1.7.0 and so on). This version already supports their new Arduino Zero Pro already on sale, while the official team's shop still has it as "Coming soon".
It is sad to see greed, egos and what-not brought to the forefront of public attention, specially regarding a product that is supposed to epitomize the Open Source Community's strength.
Anyone out there surely feels that Arduino is the original idea, perpetuated by the hard work of what is now a massive team. But above all, Arduino is but the massive community that made it what it is today !
All in all... Facepalm !

* Id advise everyone to have a scroll down the hardware index page at and scroll down for some of original boards, etc

Tuesday, 14 April 2015


A new version of the Arduino IDE (1.6.3) is available at the download page!
The Arduino IDE 1.6.3 is a bug fix release: after the already released 1.6.2 with new libraries and cores managers.