Adding sound to my train controller

Enhanced mid-range devices. PIC12F1xxx and PIC16F1xxx

Re: Adding sound to my train controller

Postby drh » Mon Jun 20, 2016 6:06 pm

You didn't enabled the IOCIE bit before the sleep command.
User avatar
drh
Verified identity
 
Posts: 61
Joined: Tue May 27, 2014 3:31 pm
Location: Hemet, Calif.
PIC experience: Professional 5+ years with MCHP products

Re: Adding sound to my train controller

Postby grandpa jay » Mon Jun 20, 2016 6:30 pm

drh
The IOCIE bit is set in the Initialization. Does it need to be set just before sleep?
Jay
grandpa jay
 
Posts: 22
Joined: Wed Sep 24, 2014 9:10 pm

Re: Adding sound to my train controller

Postby drh » Mon Jun 20, 2016 7:12 pm

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.
User avatar
drh
Verified identity
 
Posts: 61
Joined: Tue May 27, 2014 3:31 pm
Location: Hemet, Calif.
PIC experience: Professional 5+ years with MCHP products

Re: Adding sound to my train controller

Postby grandpa jay » Mon Jun 20, 2016 7:58 pm

drh
INTCON = 0b11001000; //set GIE and PEIE so TMR2 can interrupt IOCIE set
Jay
grandpa jay
 
Posts: 22
Joined: Wed Sep 24, 2014 9:10 pm

Re: Adding sound to my train controller

Postby drh » Tue Jun 21, 2016 2:50 am

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.
User avatar
drh
Verified identity
 
Posts: 61
Joined: Tue May 27, 2014 3:31 pm
Location: Hemet, Calif.
PIC experience: Professional 5+ years with MCHP products

Re: Adding sound to my train controller

Postby grandpa jay » Tue Jun 21, 2016 4:50 pm

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;
Last edited by ric on Tue Jun 21, 2016 9:24 pm, edited 1 time in total.
Reason: Placed "code" tags around the code.
grandpa jay
 
Posts: 22
Joined: Wed Sep 24, 2014 9:10 pm

Re: Adding sound to my train controller

Postby grandpa jay » Tue Jun 21, 2016 5:03 pm

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
grandpa jay
 
Posts: 22
Joined: Wed Sep 24, 2014 9:10 pm

Re: Adding sound to my train controller

Postby Roche » Tue Jun 21, 2016 7:35 pm

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
Roche
 
Posts: 72
Joined: Fri Jul 11, 2014 12:35 pm
PIC experience: Professional 5+ years with MCHP products

Re: Adding sound to my train controller

Postby grandpa jay » Tue Jun 21, 2016 9:34 pm

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
grandpa jay
 
Posts: 22
Joined: Wed Sep 24, 2014 9:10 pm

Re: Adding sound to my train controller

Postby grandpa jay » Thu Jun 23, 2016 2:29 pm

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
grandpa jay
 
Posts: 22
Joined: Wed Sep 24, 2014 9:10 pm

PreviousNext

Return to 14-Bit Core (enhanced)

Who is online

Users browsing this forum: No registered users and 1 guest

cron