Roberto Javier Weiser
Published © GPL3+

Mini Electronic Congas

I want to play the congas but they are so big and heavy! How can I carry them around - with finger-sized congas, obviously!

AdvancedShowcase (no instructions)211
Mini Electronic Congas

Things used in this project

Hardware components

Microchip dsPIC33F
×1

Story

Read more

Custom parts and enclosures

Enclosure 3D model

Schematics

Schematics

Code

main.c

C/C++
/******************************************************************************/
/* Files to Include                                                           */
/******************************************************************************/
#include <stdint.h>          /* Includes uint16_t definition                    */
#include <stdbool.h>         /* Includes true/false definition                  */
#include "system.h"          /* System funct/params, like osc/peripheral config */
#include "setup.h"           /* User funct/params, such as InitApp              */
#include "Pin_Mapping.h"     // Input pin labels
#include <xc.h>
#include "FSconfig.h"
#include "FSDefs.h"
#include "FSIO.h"
#include "GenericTypeDefs.h"
#include "HardwareProfile.h"
#include "SD-SPI.h"
#include "Play.h"
/******************************************************************************/
/* Global Variable Declaration                                                */
/******************************************************************************/
volatile int IntFlag = 0;                       //Flag indicating that an interrupt has ocurred
 
struct AudioFile
{
    const char  *name;                          //Name of file
    volatile int FPos;                          //Current position
    volatile int flag;                          //Flag indicating that the interrupt for this file has happened
};
 
struct AudioFile Conga_1 = {"Sample_1.raw",0,0};   //Name of the files in SD card
struct AudioFile Conga_2 = {"Sample_2.raw",0,0};
struct AudioFile Conga_3 = {"Sample_3.raw",0,0};
struct AudioFile Conga_4 = {"Sample_4.raw",0,0};
struct AudioFile Conga_5 = {"Sample_5.raw",0,0};
struct AudioFile Conga_6 = {"Sample_6.raw",0,0};
 
/******************************************************************************/
/* Main Program                                                               */
/******************************************************************************/
 
int16_t main(void)
{   
 
    ConfigureOscillator();         //Configure the oscillator for the device
    init_setup();                 //Initialize IO ports and peripherals
 
    while (!MDD_SDSPI_MediaDetect());
    MEDIA_INFORMATION * MDD_SDSPI_MediaInitialize();
    void MDD_SDSPI_InitIO();
    while (!FSInit());               // Initialize the library
//    while(1){PlayWithInterrupt("sine.raw");}
    while(1)
    {
        if (Conga_1.flag == 1)          //Poll flags to check which file was tirggered by interrupt
        {
            Conga_1.flag = 0;           //Reset flags
            IntFlag = 0;
            PlaySample(Conga_1.name);   //Play file
        }
        if(Conga_2.flag == 1)
        {
            Conga_2.flag = 0;
            IntFlag = 0;
            PlaySample(Conga_2.name);
        }
        if(Conga_3.flag == 1)
        {
            Conga_3.flag = 0;
            IntFlag = 0;
            PlaySample(Conga_3.name);
        }
        if(Conga_4.flag == 1)
        {
            Conga_4.flag = 0;
            IntFlag = 0;
            PlaySample(Conga_4.name);
        }
        if(Conga_5.flag == 1)
        {
            Conga_5.flag = 0;
            IntFlag = 0;
            PlaySample(Conga_5.name);
        }
        if(Conga_6.flag == 1)
        {
            Conga_6.flag = 0;
            IntFlag = 0;
            PlaySample(Conga_6.name);
        }
 
      Idle();       //Set MCU in idle mode to save power
      Nop();
    }
}
 
int CheckFlag(void)
{
    if(IntFlag == 1)        //Check if IntFlag is high
    {return 1;}
}
 
void __attribute__((interrupt, no_auto_psv)) _CNInterrupt(void)
{
    if(TMR1>15600)                          //if TMR1 is less than 10 ms (prevents debouncing)
    {
        Conga_1.flag = 0;                   //Reset flags
        Conga_2.flag = 0;
        Conga_3.flag = 0;
        Conga_4.flag = 0;
        Conga_5.flag = 0;
        Conga_6.flag = 0;
        if(VT1 == 1){Conga_1.flag = 1;      //Check if pin is high
        IntFlag = 1;                        //Set interrupt flag high
        TMR1 = 0;                           //Reset TMR1
        goto end;}
        if(VT2 == 1){Conga_2.flag = 1;
        IntFlag = 1;
        TMR1 = 0;
        goto end;}
        if(VT3 == 1){Conga_3.flag = 1;
        IntFlag = 1;
        TMR1 = 0;
        goto end;}
        if(VT4 == 1){Conga_4.flag = 1;
        IntFlag = 1;
        TMR1 = 0;
        goto end;}
        if(VT6 == 1){Conga_6.flag = 1;
        IntFlag = 1;
        TMR1 = 0;}
    }
    end:
    IFS1bits.CNIF = 0;                      // Clear CN interrupt
}
 
void __attribute__((interrupt, no_auto_psv)) _INT4Interrupt(void)
{
    if(TMR1>15600)
    {
        Conga_1.flag = 0;
        Conga_2.flag = 0;
        Conga_3.flag = 0;
        Conga_4.flag = 0;
        Conga_5.flag = 0;
        Conga_6.flag = 0;
        Conga_5.flag = 1;
        IntFlag = 1;
        TMR1 = 0;
    }
    IFS3bits.INT4IF = 0;            //Clear the INT4 interrupt flag
}

Credits

Roberto Javier Weiser

Roberto Javier Weiser

1 project • 0 followers
Electronics Design Engineer. Automotive, power, audio, renewable energies

Comments