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.