Page 2 of 4

Re: Adding sound to my train controller

PostPosted: Fri Jun 10, 2016 10:41 pm
by grandpa jay
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

Re: Adding sound to my train controller

PostPosted: Sat Jun 11, 2016 2:00 am
by drh
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.

Re: Adding sound to my train controller

PostPosted: Sun Jun 12, 2016 8:43 am
by ric
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.

Re: Adding sound to my train controller

PostPosted: Mon Jun 13, 2016 2:11 pm
by grandpa jay
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

Re: Adding sound to my train controller

PostPosted: Mon Jun 13, 2016 4:20 pm
by drh
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. ;)

Re: Adding sound to my train controller

PostPosted: Sat Jun 18, 2016 11:17 pm
by grandpa jay
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

Re: Adding sound to my train controller

PostPosted: Sun Jun 19, 2016 2:58 pm
by drh
Yes.

Re: Adding sound to my train controller

PostPosted: Sun Jun 19, 2016 9:40 pm
by grandpa jay
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

Re: Adding sound to my train controller

PostPosted: Sun Jun 19, 2016 11:35 pm
by jtemples
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.

Re: Adding sound to my train controller

PostPosted: Mon Jun 20, 2016 5:53 pm
by grandpa jay
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