Page 3 of 4

Re: Adding sound to my train controller

PostPosted: Mon Jun 20, 2016 6:06 pm
by drh
You didn't enabled the IOCIE bit before the sleep command.

Re: Adding sound to my train controller

PostPosted: Mon Jun 20, 2016 6:30 pm
by grandpa jay
drh
The IOCIE bit is set in the Initialization. Does it need to be set just before sleep?
Jay

Re: Adding sound to my train controller

PostPosted: Mon Jun 20, 2016 7:12 pm
by drh
Nope. You configured the polarity but not the IOCIE. Unless the code you posted is not current. If you can monitor the OSC2 pin with a scope, you can verify the clock stops when it should be sleeping.

Re: Adding sound to my train controller

PostPosted: Mon Jun 20, 2016 7:58 pm
by grandpa jay
drh
INTCON = 0b11001000; //set GIE and PEIE so TMR2 can interrupt IOCIE set
Jay

Re: Adding sound to my train controller

PostPosted: Tue Jun 21, 2016 2:50 am
by drh
Okay, I would have done it differently. You also need to clear the IOCBF4 flag after you wake up. I would also clear the enable bit also, and re-enable just before "attempting" to sleep. Based on a previous post, you may not be entering sleep.

Re: Adding sound to my train controller

PostPosted: Tue Jun 21, 2016 4:50 pm
by grandpa jay
drh
I may have found something. When I reset GIE things stop. This is my testing using the RedSig being added at different points.
Jay
Code: Select all
void start_train(void) {
    RedSig = 0; // Red off                                                         
    GrnSig = 1; // Set Green
    __delay_ms(2000); // for about 2 sec.
    Sound = 0; // Turn sound on
    __delay_ms(100); // for about 0.1 sec. short pulse required
    Sound = 1; // Sound off
    INTCONbits.GIE = 0; // prevent branches to the interrupt address (0004h).
    INTCONbits.IOCIE = 1;   //Set IOC enable
    RedSig = 1; // This happens [b]Test 1[/b]
    SLEEP();       // Put it to sleep wakeup on busy pin going high RB4
    RedSig = 0; // This happens [b]Test 2[/b]
    //INTCONbits.GIE = 1; Test 5 commented out, program steps thru but rest will not work without GIE
    __delay_ms(1000); [b]added just in case[/b]
    RedSig = 1; //This does not happen [b]Test 4[/b]
    INTCONbits.IOCIF = 0;// Clear the flag
    INTCONbits.IOCIE = 0;// Clear enable
    RedSig = 1; //This does not happen [b]Test 3[/b]
    START = 1;

Re: Adding sound to my train controller

PostPosted: Tue Jun 21, 2016 5:03 pm
by grandpa jay
drh
I moved the INTCONbits.GIE = 1; to after the call to start the train and it appears to work. But does not cure the static on the sound. May have to go to a separate supply. The sleep is acting as a delay until the recorded sound is finished. That a good thing. I will leave it in.
Jay

Re: Adding sound to my train controller

PostPosted: Tue Jun 21, 2016 7:35 pm
by Roche
grandpa jay wrote:drh
I moved the INTCONbits.GIE = 1; to after the call to start the train and it appears to work. But does not cure the static on the sound. May have to go to a separate supply. The sleep is acting as a delay until the recorded sound is finished. That a good thing. I will leave it in.
Jay


As an alternative to a separate supply, you could try decoupling it - say a 47 ohm resistor in the supply line to the MP3 device and a 100uF capacitor directly across the MP3 device supply

Re: Adding sound to my train controller

PostPosted: Tue Jun 21, 2016 9:34 pm
by grandpa jay
Roche
I will give that a try, Thank You. Another issue has appeared. When I program with the PICkit3, The first time that I run the program I get the delay start at the end of the sound as expected. When I run thru the rest of the program and do a restart, I do not get the delay.
Jay

Re: Adding sound to my train controller

PostPosted: Thu Jun 23, 2016 2:29 pm
by grandpa jay
I tried a 33 Ohm resistor, could not find a 47 Ohm. I think that it dropped the voltage to low? It would not play.
If I go to a separate power supply, what would be the best way to trigger the MP3 module? I am thinking a relay but not being electronic minded I am not sure. Could I use an optical isolater?
Jay