Adding sound to my train controller

Enhanced mid-range devices. PIC12F1xxx and PIC16F1xxx

Re: Adding sound to my train controller

Postby grandpa jay » Fri Jun 10, 2016 10:41 pm

drh
That was a good idea. Removing the PIC and triggering the sound, there is no static. I replaced the PIC, and manually triggered the sound, and the static is back.
About the crappy layout, I have no idea what a good layout should look like. My background is mechanical engineering. The layout is just where it would fit.
Jay
grandpa jay
 
Posts: 22
Joined: Wed Sep 24, 2014 9:10 pm

Re: Adding sound to my train controller

Postby drh » Sat Jun 11, 2016 2:00 am

Here is PCB tutorial: http://documents.mx/documents/pcb-design-tutorial-rev-a.html
Basically, keep the analog (audio) circuits away from the digital circuits as much as possible.

If the PIC does not need to be doing anything while the sound is playing, you might be able to put it to sleep
for the duration of the sound, then wake up.
User avatar
drh
Verified identity
 
Posts: 55
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 ric » Sun Jun 12, 2016 8:43 am

The most important wires to look at are your power wires, and particularly the ground tracks.
As mentioned by DRH, you should keep your audio tracks well away from your other tracks. You have your MP3 player right next to your relay control chip.
You also need a lot more bypass capacitors (about 100nF) connected very close to the power pins of each chip.
Latest test project, an LED matrix display made from one reel of addressable LEDs. here
User avatar
ric
Verified identity
 
Posts: 398
Joined: Sat May 24, 2014 2:35 pm
Location: Melbourne, Australia
PIC experience: Professional 5+ years with MCHP products

Re: Adding sound to my train controller

Postby grandpa jay » Mon Jun 13, 2016 2:11 pm

drh
I like the idea of putting the PIC to sleep. I have never used sleep before. The sound module has a busy pin that may be used. The pin is low if playing sound and high if not. Could this be used as an on/off for sleep? If not it looks like timer 1 could be used, but have no idea how to do it.
Any help will be appreciated.
Jay
grandpa jay
 
Posts: 22
Joined: Wed Sep 24, 2014 9:10 pm

Re: Adding sound to my train controller

Postby drh » Mon Jun 13, 2016 4:20 pm

You can wake up from sleep with interrupts from the INT pin (RA2) or an IOC pin. The easiest to use would be the INT input but you are already using that. The only pin you have available is RB4 which can be configured as an Interrupt On Change input. Study section 13 of the data sheet for IOC and section 9 for sleep.

Another thing to consider is you may be able to reduce or remove the noise by running the PIC at a different speed Of course, this may screw up whatever else the code needs to be doing. ;)
User avatar
drh
Verified identity
 
Posts: 55
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 » Sat Jun 18, 2016 11:17 pm

drh
Thank you for the help. Been on vacation for a week. I will try the IOChange. This is what I have found, and needs to be included in the program.
The busy pin is low when playing and goes high when finished. The sleep step should be entered just after the Sound off pulse?
IOCBP4 = 1 Positive going edge on RB4
IOCIE = 1 IOC enabled if set
TRISB4 = 1 RB4 set as input
_asm sleep _endasm Put it to sleep
Does this make sense?
Jay
grandpa jay
 
Posts: 22
Joined: Wed Sep 24, 2014 9:10 pm

Re: Adding sound to my train controller

Postby drh » Sun Jun 19, 2016 2:58 pm

Yes.
User avatar
drh
Verified identity
 
Posts: 55
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 » Sun Jun 19, 2016 9:40 pm

drh
When entering the data into the program, I come up with a question. If I set IOCIE, is this going to cause an interrupt that has not been handled? I have the GIE & PEIE bits set for timer 2 rollover with a debounce setup. This is as the 13.1 datasheet indicates.
Does the 13.5 Operation in sleep say that the IOCIE does not need to be set if the edge detect is set? The edge detect will wake the processor from sleep by its self.
Jay
grandpa jay
 
Posts: 22
Joined: Wed Sep 24, 2014 9:10 pm

Re: Adding sound to my train controller

Postby jtemples » Sun Jun 19, 2016 11:35 pm

grandpa jay wrote:If I set IOCIE, is this going to cause an interrupt that has not been handled? I have the GIE & PEIE bits set

I don't know what you mean by "has not been handled", but if GIE, IOCIE, and IOCxF are all set, the PIC will branch to the reset vector. There aren't any other conditions required or any special cases; it doesn't matter what order those bits get set. They're simply ANDed together.

Does the 13.5 Operation in sleep say that the IOCIE does not need to be set if the edge detect is set?

No. It says that IOCxF will already be set when your first instruction after the SLEEP instruction executes, meaning you can safely test its state without having to wait. No peripheral's interrupt will wake the PIC from sleep unless the associated IE and IF bits are both set (and PEIE if applicable). The GIE bit is not required for wake from sleep.
jtemples
Verified identity
 
Posts: 162
Joined: Sun May 25, 2014 2:23 am
Location: The 805
PIC experience: Professional 5+ years with MCHP products

Re: Adding sound to my train controller

Postby grandpa jay » Mon Jun 20, 2016 5:53 pm

Gentlemen
I have added the sleep to the program, but I think that it is not waking up as the start train is not being energised.
The last thing that happens is the sound starts and plays with the static. The busy pin goes high (4.0v) after the sound stops. I expected this to trigger the wakeup. It may be that the sleep is not going to help reduce the sound static.
Jay
Attachments
TCwS.c
(10.38 KiB) Downloaded 52 times
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