Close

Hitting a note, some positive results!

A project log for Case study: A polyphonic PIC18F music box

Does this work? An online article discusses about building this music box.

nyh-workshopNYH-workshop 11/28/2017 at 13:290 Comments

After adding a 100nF capacitor in between the 100K resistor and the scope input, the DC is remove, left the square wave centered, peak to peak around +4 and -4V. Fair enough.

The reason of the previous log' incomplete decaying of the amplitude is due to the Analog Discovery 2's I/O tool which doesn't supply the full +5V on it. When I connect the +5V supply in their "Supplies" tool, the whole decay is complete!

There is a huge jolt when the note is struck. I'm also investigating that a bit. I have programmed a simple run where it keeps hitting and releasing the note at 500Hz. The code is as follows (use MikroC, within the Demo limit!) :

void timer1interrupt() iv 0x0004 ics ICS_AUTO {

     TRISA.TRISA4 ^= 1;
     //PORTA.RA4 ^= 1;
     TMR1 = 64536;
     PIR1.TMR1IF = 0;
}


void init() {

    //OSCCON.SPLLEN = 1;      // PLL turned off.
    //OSCCON.IRCF = 0b1110;   // 8mhz internal oscillator.
    //OSCCON.SCS = 0b10;


    OSCCON.SPLLEN = 0; // disable Software PLL.
    OSCCON.IRCF3 = 1;  // 8mhz -> 32mhz if PLLx4 set.
    OSCCON.IRCF2 = 1;
    OSCCON.IRCF1 = 1;
    OSCCON.IRCF0 = 0;
    OSCCON.SCS1  = 0;  // system clock select: internal osc.
    OSCCON.SCS0  = 0;

    APFCON.P1SEL = 0;
    APFCON.P2SEL = 1;
    ANSELA = 0x00;
    TRISA = 0x00;
    LATA = 0b00010000;

    INTCON = 0x00;

}

void init_intr() {
     // Please look at the datasheet for the PIC12F1572 for more info!
     PIR1 = 0x00;
     PIE3 = 0x00;
     PIE1.TMR1IE = 1;
     INTCON.PEIE = 1;
     INTCON.GIE = 1;
}

void init_timer1() {
    // Timer1 clock source follows instruction clock!
    T1CON = 0x00;
    T1CON.T1CKPS0 = 1;     // 1:8 prescale value.
    T1CON.T1CKPS1 = 1;
    TMR1 = 64536;
    T1GCON = 0x00;
    T1CON.TMR1ON = 1;
}

void main() {

     init();

    delay_ms(50);

    init_intr();
    
    PORTA.RA5 = 0;
    
    init_timer1();
    
    while(1) {
         TRISA.TRISA5 = 1;
         delay_ms(2500);
         TRISA.TRISA5 = 0;
         delay_ms(100);
    
    }

}

And here it goes, it keeps hitting the note and decays for 2.5 seconds over and over again. 

Now I'm gonna attach the thing to the cheap LM386 module I have here and hear it. Hopefully it'll be good this time! :)

Discussions