Connecting PWM inputs in parallel

GAP

Senior Member
Hi,

I want to run 2 picaxe 08M2's from the one PWM source.

I have a remote control driving a motor in a model train which uses a picaxe to drive a relay to give me direction control.

The picaxe monitors the PWM looking for a command which toggles the relay.

I also have a diesel simulator using a picaxe sound generated card that varies in line with the PWM signal.

I have run the 2 circuits separately and they both work.

When I connected them to the same point the 2 picaxes seem to interfere with each other, with the sound cutting out and not changing in line with the PWM signal..

The relay drive is connected via a 1K resistor and the sound is connected by a 12K /47uF RC network to the same PWM point.

The input at the sound card is a varying DC voltage the product of the RC network.

I am wondering if the RC network is introducing some form of interference or a loading issue.

I did try to connect the sound card to the motor output during development but it is a level of -12V and the signal is inverted and it became to cumbersome for my limited skills.

The PWM point is the input to the motor drive FET and is a +5V signal.

Am I on the right track and if so any suggestions are more than welcome.

Thanks in advance.

Graeme
 

Goeytex

Senior Member
A picture is worth a thousand words. Please take the time to post a schematic diagram that will allow others to help you.

Your terminology is somewhat confusing. A Picaxe cannot "run" from a PWM source.

The picaxe monitors the PWM looking for a command which toggles the relay.
A PWM signal does not typically have commands embedded in it. Perhaps the signal is something else ?

What is the actual source of the signal that you are referring to as "PWM" ?
 

westaust55

Moderator
In general it is possible within the "loading" capabilities of a signal to distribute that signal to multiple other chips (eg PICAXE inputs).
That is usually referred to the "Fan Out".

I presume that by "run from PWM" that you are using the PULSIN command to determine the pulse duration and have the programs act accordingly?

In addition to your schematic as already requested, you should post your program code to avoid confusion over how you are implementing the actions.
 

GAP

Senior Member
I am reading ADC10 from the same point.

At present I cannot send a schematic as I am on the road till near months end.

Below is a copy of the direction control code taken from "trainelectronics.com"

This is the direction control code.

'08M from 12F683 code
'd. bodnar 7-3-13

Symbol Relay = 2 'pin 5 hpwm 1
Symbol Temp1= w8
Symbol temp2 = b2
Symbol SawOff =bit1
Symbol HaveToggled = bit2
Symbol RelayBit = bit3 'saved so the relay resets to what it was when power was turned off

Sertxd (10,13,"d. bodnar Ver 1.0 E-Unit",10,13)
Sertxd (10,13,"07-03-13",10,13)
Sertxd (10,13,"E-unit for RC board - saves prior state of relay",10,13)


read 0,relaybit
Sertxd ("relaybit = ",#relaybit,10,13)
if relaybit = 0 then
high Relay
else
low Relay
endif
havetoggled = 1
sawoff = 0
'if we see 20 zeros then we know it has been off
' in that case set a flag so that the next time we see a non zero we
' toggle the relay
Start:
for temp2=1 to 20
readadc c.4, temp1 ''read pin 3 PWM
if temp1 <> 0 then skipout:
next temp2
sawoff = 1

havetoggled = 0
goto start:

SkipOut:


if HaveToggled = 0 then
toggle Relay
if relaybit = 0 then
relaybit = 1
else
relaybit = 0
endif
write 0, relaybit 'save relay state so it starts in the same direction
'if power fails
Sertxd ("TOGGLED ",10,13)
HaveToggled = 1
endif

sawoff=0
goto start:


Basically the sound is a program that reads the ADC voltage and alters an EXOR output to change the pulse rate.

So I am connecting 2 ADC10 inputs to the same point.

When I get back home I will try to send schematics and code.
 

geoff07

Senior Member
Your terminology is confusing us:

- an ADC input reads an analogue voltage and tells the program the value.
- a PWM signal is a digital pulse-width modulated pulse sequence, used to vary power whilst maximising torque/led brightness/etc. and is usually an output to a device, not a signal to a chip.

You don't read PWM signals using an ADC, or, indeed, at all.

If you can summarise a) what you are aiming to achieve, b) what the inputs are and c) what the outputs should be and d) what you mean by PWM, then it will be easier to understand what you are doing.

My reading of what you are doing, and which may well be wrong, is:

- you have a train set
- you want to control the train's direction of motion using a remote control
- you want to play a sound that changes according to the direction
- the problem is related to connecting them so they can both work together

If you can clarify this it should make it easier to help you.
 

hippy

Technical Support
Staff member
Below is a copy of the direction control code taken from "trainelectronics.com"
A link to exactly where that came from the site would probably be useful for others to understand what it relates to.
 

MPep

Senior Member
You don't read PWM signals using an ADC, or, indeed, at all.

Technically, you can but ONLY if the output has a resistor and capacitor combination to convert to an analogue voltage, which is then read by ADC.
See here for an example. Yes I realise it indicates a BASIC St..p but the principle is what matters here.
 

GAP

Senior Member
A link to exactly where that came from the site would probably be useful for others to understand what it relates to.
This is a link to the article that I followed to build the controller
http://www.trainelectronics.com/Articles/RadioControl-LED-8Amp/index.htm

The point labelled PWM is where I am taking the signal from I am using the +5V for my sound card picaxe as well.

The input to the sound card connects there as well, there is a 12K 47uF RC network that converts the PWM to a DC voltage that varies in line with the PWM pulse width on the sound card input.

As I understand it the controller picaxe looks for the signal sent when the ON/OFF button is pressed to toggle the relay.
 

Goeytex

Senior Member
So it seems the "PWM" is really a DC voltage as a result of a PWM conditioned by a low pass filter. This signal cannot source very much current. ( < 500 microamps?) .

The Picace ADC input will be high impedance and should not significantly affect the DC voltage. However we do not Know the input impedance of the other device connected to this point. My guess is that the other device is affecting the signal ( DC level) do to its input impedance being rather low.

My suggestion is to put a rail-to-rail op amp (configured as a voltage follower) between the "PWM" point and the two devices.

The input impedance specification of the sound card would be helpful.

Question: Why are we connecting a DC voltage to a sound card input ?
 
Last edited:

Bill.b

Senior Member
You could try a diode in series with the R/C filter.
This would prevent the DC across the capacitor from affecting the PWM signal.

The diode would decrease the available voltage across the capacitor therefore the
analogue input to the second picaxe, but this can be compensated for within the program.

2PWM.jpg

Bill
 

AllyCat

Senior Member
Hi,

Hmm, I wouldn't recommend that circuit. The capacitor will just charge up to the highest voltage on the "PWM" input (less one diode drop, ~0.6 volt) but there is no resistance to pull it down again so it may stay high for a L-O-N-G time.

If the "PWM" is a real (switching) output then it will have low output impedance so can "fan out" to as many inputs as you're likely to need.

If the "PWM" is actually via a low-pass filter, then the "source resistance" will be that of the resistor. But the PICaxe A/D input pins have high input impedance so you can still "safely" fan out to several input pins.

However, in either case, I would connect a separate resistor of perhaps 1k ohm in series with each PICaxe input pin, just in case input pins are "accidentally" programmed as outputs (which could cause a damaging current to flow).

If you actually want a switching input signal to the first PIcaxe and an analogue signal to the second, then just remove (short-out) the diode in the diagram.

Cheers, Alan.
 
Last edited:

hippy

Technical Support
Staff member
When I connected them to the same point the 2 picaxes seem to interfere with each other, with the sound cutting out and not changing in line with the PWM signal.
It seems we are focused on the relay controller, but the problem is with the sound circuit and its operation.

It would be best to post details of the sound controller program and its circuit.
 

Goeytex

Senior Member
It seems we are focused on the relay controller, but the problem is with the sound circuit and its operation.
I agree.

The best I can glean from the OP's comments is that when 2 Picaxe ADC inputs are connected to a certain point on the controller board, the sound stops working. However, we do not know where the sound connection is made. Neither do we have any details of the sound device. It is crystal ball mode.

The OP mentioned a low pass filter of 12K and 47uf. So based upon this, I am guessing that the circuit is something like Figure 1.
The problem is when both ADC's are connected the sound no longer works. However, it works when only one of the ADC's is connected.

Guessing again, it seems that connecting both ADC's is loading the circuit to the point that the PWM at the sound input insufficient. If this is the case, then it seems to me that the PWM signal is very weak and cannot source enough current to drive the circuity when loaded with 2 ADC's.

If the crystal ball is working then one solution might be shown in Figure 2.
 

Attachments

SAborn

Senior Member
My understanding is much different than the later views, from what i read was when the RC circuit was connected the PWM to other parts of the circuit was not evident.

So to me the RC circuit is simply smoothing the PWM to an analog value and not allowing a PWM signal to other circuits.

As it would seem the PWM is required for motor speed control and sound card control, and its just when the RC circuit is enabled all else stops working.
 

hippy

Technical Support
Staff member
So it seems the "PWM" is really a DC voltage as a result of a PWM conditioned by a low pass filter.
From the link given in post #11 it appears not. Looking at the PCB of the LED dimmer it seems to be a MOSFET switched PWM output from the input voltage, traditional PWM on-off control, no RC circuit to create a voltage in sight, neither in the LED dimmer nor the PIC / PICAXE circuits.

The original designer seems to be using ADC to read the PWM as a digital input high or low signal ( or more correctly voltage connected or open circuit ), perhaps as a misunderstanding as to how otherwise to do that, or to overcome issues with the way the circuit may behave when trying to read a high-side switched voltage without any obvious pull-downs in place.

My initial assessment would be that it's a flawed design.

Added: The OP does however appear to be using some sort of RC to convert PWM to a voltage.
 
Last edited:

Goeytex

Senior Member
You may be right. However if that is the case then according to the photos, a direct PWM signal is being applied to a Picaxe ADC via a 1K resistor.

I doubt we will ever know what is really going on until the OP can provide a good schematic diagram. The whole setup is a multitude of hacks and is near impossible to follow from the links.

However, in a general sense, an OP AMP between a weak ( low current) signal and the two circuit connections may solve the problem
 

AllyCat

Senior Member
Hi,

Looking at the link posted by the OP, it appears that the "PWM" is indeed a "raw" PWM pulse signal, but the adapted PICaxe code uses (mistakenly) a READADC (instead of a simple IF PINC.4 = 0) to detect it. I believe that the following is the "active" part of the code; note that it only tests for a value of zero!
Code:
sawoff = 0
'if we see 20 zeros then we know it has been off
' in that case set a flag so that the next time we see a non zero we
' toggle the relay
Start:
for temp2=1 to 20

[B][B]readadc c.4, temp1 ''read pin 3 PWM
if temp1 <> 0 then skipout:[/B][/B]

next temp2
sawoff = 1
havetoggled = 0
goto start:

SkipOut:
However, that shouldn't stop the circuit working, but we haven't been told anything about "the soundcard". Where is its input connected, what does it need and what does it actually do? My guess is that it's edge-triggered and adding an R-C filter has killed its triggering.

Basically, the functionality looks quite "simple", so I'd be very reluctant to recommend adding an Op-Amp, rather than correcting whatever is the fundamental issue. And an op-amp's offset, or a lack of full rail-rail swing, may well stop that READADC (=0) from working at all!

Cheers, Alan
 

Goeytex

Senior Member
I saw that part of the code and deduced that the ADC was being used to read the "filtered" PWM (DC) so that if the PWM was present (ADC > 0) then the Picaxe takes some action. I considered and then rejected the idea that a raw PWM was connected to and being read by an ADC as this would be a very bad idea.

In any case, 20 - 30mv of offset above GND is rather irrelevant. If the Picaxe is testing the ADC for a dc voltage ( filtered PWM) to detect the presence of a PWM signal ( motor running) and an OP-AMP is used, then code could be easily modified to " if ADC VAL > 10 then whatever".

Assuming a decent "rail-to-rail OP-AMP
 

hippy

Technical Support
Staff member
Looking at the link posted by the OP, it appears that the "PWM" is indeed a "raw" PWM pulse signal, but the adapted PICaxe code uses (mistakenly) a READADC (instead of a simple IF PINC.4 = 0) to detect it.
I posted the same but that cross-posted with others who pointed out that the OP does mention some RC producing a voltage. I therefore deleted the post as it wasn't helpful - But that's not to say your post isn't helpful ! And I have also restored my own post.

What it highlights is that we don't really have enough information on what the OP actually has, second-guessing from 'based on this...' isn't the same as clearly understanding what the full setup is.
 

AllyCat

Senior Member
Hi,

... code could be easily modified to " if ADC VAL > 10 then whatever".
Yes, of course the code could be modfied (by you or I, at least) as required.

However, it could be argued that the "reference" code being used by the OP contains four (potential) "errors" in just those two highlit lines: i.e Reading an A/D input and testing only for zero, "Pin 3" ideally sould be called "Leg 3", and the "<" and ":" are both redundant. Not "fatal" flaws, but suggestive of a not very high level of expertise in PICaxe programming (or understanding?).

Cheers, Alan.
 

Rick100

Senior Member
I built an RC speed controller for my brothers garden railroad several years ago. I recall the engine ran on approximately 18 volts. Makes me wonder what voltage is being fed to the Picaxe through the 1k resistor.

Edit:
After looking at the description of the circuit closer, it looks like the PWM signal being read is 5 volts. Could the OP confirm this is the circuit and remote he is using?
 
Last edited:

Dartmoor

Member
I hope this is relevant!
This thread is interesting to me, as one of my projects is aiming to achieve something similar.
However, going completely back to basics, I plan to achieve speed(pwm), direction & sound all in the same picaxe (08M2) chip.
I am using 3 loops. One for reading the remote control input and setting a value for two variables defining speed & direction. A second loop to set the pwm output depending on the variable value (separate loop avoids issues with the 'wait' command I use in the remote control reading). The third loop will also read the variable which defines pwm rate and set the sound output to match. The latter I still need to do & so would be interested in the code for your sound card.

What I was trying to say is that perhaps some 'lateral thinking' may help and putting all in one chip may be the simplest answer?
As an aside, the relay is the easiest way to achieve reversing. When using an 'H bridge', there is the added complication of having to invert the PWM values in reverse (unless there is an easy solution that I missed?).
 

GAP

Senior Member
I hope this is relevant!
This thread is interesting to me, as one of my projects is aiming to achieve something similar.
However, going completely back to basics, I plan to achieve speed(pwm), direction & sound all in the same picaxe (08M2) chip.
I am using 3 loops. One for reading the remote control input and setting a value for two variables defining speed & direction. A second loop to set the pwm output depending on the variable value (separate loop avoids issues with the 'wait' command I use in the remote control reading). The third loop will also read the variable which defines pwm rate and set the sound output to match. The latter I still need to do & so would be interested in the code for your sound card.

What I was trying to say is that perhaps some 'lateral thinking' may help and putting all in one chip may be the simplest answer?
As an aside, the relay is the easiest way to achieve reversing. When using an 'H bridge', there is the added complication of having to invert the PWM values in reverse (unless there is an easy solution that I missed?).

Sorry for the delay been away on duty.

This is the code for the sound card.

Code:
'Hustler sound

'Basic Picaxe Diesel Sound derived from Greg Hunter's Yellow Diesel 12/2/10
'and installed into Hustler Diesel

'Diesel engine sound -  6 STEPS of speed


'constant "fast idle" when decelerating until speed falls below '60'
'+++++++REMOVED Fast Idle+++++++++++


'assume an analogue voltage on pin1 - 0 to 5.0 = max speed.

'5 stage shift register. bits 4 & 5 EXORed and fed back to input bit

'pin 1 is speed volts input

'pin0 is output to speaker

symbol seed=b0   'shift register

seed=56           'initialize - can be any number except 0 and 255
                   'from Greg 53 is slow, 36 is fast, 56 is pulsy fast
                   
			

symbol speed=w1   'speed volts input 0-5.0 =0 to 1023 has to be a word, 
			'so w1=b2+b3

symbol paustime=b6   'timer to determine rate of sound (pause).


symbol oldspeed=b5
                                            

symbol DECEL=b7
                                            
                                            
'==================================================================

setfreq M8  'sets frequency to 8MHz

pause 1000  'delay to let capacitor charge and not sound horn on turnon   

start:
	seed=seed*2               'shift left 1 bit
	if bit4=bit5 then eXOR    'do an EXOR
	LOW 0
	bit0=0
	goto MotSpeed

eXOR:bit0=1
	HIGH 0
	bit0=1

 
MotSpeed:
	
	readadc10 1,speed   'read speed into w1 - 15 steps of 'speed'

	speed=speed/4       'speed now around 0-160 again.

	if oldspeed>speed then slowing
	if oldspeed=speed and decel=1 then slowing    'so must be accelerating or at 
	                                              'steady speed but was last 
	                                              'accelerating

accel:
	DECEL=0

looper: 
	oldspeed=speed 
	b4=speed+30/41 '31 gave max at 3.5V then idle, 41 gives max at 5V


	'lookup b4,(36,20,14,8,4,2,1),paustime  'idle + 6 steps of speed
	
	lookup b4,(42,32,20,10,5,2,1),paustime 'experimented with table numbers 
							  'to get different revs
	

paus:
	pause paustime
	goto start




slowing: 
	DECEL=1
	'if speed<60 THEN looper
	 'paustime=18	'decelerate at higher speeds gives constant 'fast idle'
	 			'===== changed from 14 to 18 to match lookup table =======
	 			'*****Fast idle removed****
	goto looper
		
		
oldspeed=speed
goto paus
Attached is a schematic of the sound card the input labelled PWM attaches directly to the PWM point on the motor controller.

hustler rc sound.JPG
 

Rick100

Senior Member
Going back to your first post:
I have run the 2 circuits separately and they both work.
When I connected them to the same point the 2 picaxes seem to interfere with each other, with the sound cutting out and not changing in line with the PWM signal..
Since you don't know how much load you can put on the PWM output from the dimmer control, you might try putting a buffer like a 74hc14 between the PWM and the Picaxes your driving. Each Picaxe could be driven from a separate output from the buffer. It should be easy enough to try.
 

Goeytex

Senior Member
@GAP,

I thought you said two connections were made to the PWM point? The schematic only shows 1 connection.

There is nothing in the code to tell Picaxe Pin C.1 ( Leg 5) to do anything yet there is a connection to a diode. This pin will float. What is purpose of the Diode and 1K resistor?

What is the voltage level of the PWM signal (green wire) ?

It was previously stated that the capacitor was 47uF. The schematic shows 4.7uF which makes more sense. Which one is correct?

How is the motor/ motor driver getting a PWM signal? There is nothing in the schematic showing a "PWM" to the motor.

IF IF IF, the PWM at the point labeled PWM is 12V then the Picaxe internal ESD diodes will clamp the voltage at the pin to ~ 5.5 volts. In other words the DC level to the Picaxe will reach 5v when the PWM is at ~ 45% duty cycle ( about 1/2 speed). Is this what you want?
 

GAP

Senior Member
@GAP,

I thought you said two connections were made to the PWM point? The schematic only shows 1 connection.

There is nothing in the code to tell Picaxe Pin C.1 ( Leg 5) to do anything yet there is a connection to a diode. This pin will float. What is purpose of the Diode and 1K resistor?

What is the voltage level of the PWM signal (green wire) ?

It was previously stated that the capacitor was 47uF. The schematic shows 4.7uF which makes more sense. Which one is correct?

How is the motor/ motor driver getting a PWM signal? There is nothing in the schematic showing a "PWM" to the motor.

IF IF IF, the PWM at the point labeled PWM is 12V then the Picaxe internal ESD diodes will clamp the voltage at the pin to ~ 5.5 volts. In other words the DC level to the Picaxe will reach 5v when the PWM is at ~ 45% duty cycle ( about 1/2 speed). Is this what you want?
The PWM point is the on the motor controller please refer to the "trainlectronics" article.
This is the input to the FET that drives the motor via the picaxe controlled relay, it is connected to the reverser drive picaxe via a 1K resistor, the sound card input connects to the same point.
The 5V and ground are all taken from their respective points on the motor controller card.
 

Goeytex

Senior Member
You really need to take the time to do up a complete and accurate schematic. I cannot make any sense of your schematic as it is incomplete and does not show all connections.

I asked you a straight forward question about the PWM voltage level on the green wire. You did not answer.
I also asked which value of capacitor was correct. You did not answer that either.
The best I can tell is that you have not tried any of the suggestions offered so far. At least you have not indicated that you have by some kind of acknowledgement.

Three pages of posts and I am still not clear about what connected to what causes the problem.

What we have here is a failure to communicate.
 

GAP

Senior Member
You really need to take the time to do up a complete and accurate schematic. I cannot make any sense of your schematic as it is incomplete and does not show all connections.

I asked you a straight forward question about the PWM voltage level on the green wire. You did not answer.
I also asked which value of capacitor was correct. You did not answer that either.
The best I can tell is that you have not tried any of the suggestions offered so far. At least you have not indicated that you have by some kind of acknowledgement.

Three pages of posts and I am still not clear about what connected to what causes the problem.

What we have here is a failure to communicate.

"You really need to take the time to do up a complete and accurate schematic. I cannot make any sense of your schematic as it is incomplete and does not show all connections."

A. The drawing posted is a combination of the sound card schematic and the block diagram of the train set up, the motor controller block was used to save posting a schematic that was readily available on the net and could have been be read in conjunction with the diagram in the article in the link posted previously.
It is the diagram I used to construct the setup by looking at and combining the two schematics as the build progressed. I surmised that the technical expertise of most readers could follow this with no issue.

"I asked you a straight forward question about the PWM voltage level on the green wire. You did not answer."

A. the voltage is 0-5V it is the drive on the gate of the output FET that drives the motor.

"I also asked which value of capacitor was correct. You did not answer that either."


A. The original capacitor value was from memory, the schematic is a true representation of what has been constructed.


"The best I can tell is that you have not tried any of the suggestions offered so far. At least you have not indicated that you have by some kind of acknowledgement."

A. As previously stated and apologized for I have duties to perform that take priority over my hobbies and yes in my limited time off I have tried the suggestions.


"What we have here is a failure to communicate"

A. May I ask if you looked at the article link posted in post #11 under "Using a PICAXE for the Reversing Circuit" that showed the reverser schematic with the PWM connection point quite clearly marked. May I suggest that maybe what we have here is maybe a failure to read all information pertinent to the question and making judgments.

At this point in time I am feeling quite insulted by this post only my forum etiquette is holding me back from speaking my mind.

If this is the sort of answer, laced with snide comments, a learner trying to expand their knowledge and trying to come to grips with the terminology gets from members from this forum then maybe I should just stop asking questions.

Finally I would like to say thanks to those member who offered suggestions and just say that after some experimentation I finally solved the problem myself.

I made a fundamental beginners error and did not tie the "Serial In" Leg2 to either high or low and left it floating.

After tying it to ground via a 22K resistor the setup works effectively with only sound interrupt is when the power button to change direction is pushed and I can live with that.

Sorry for being such a burden.
 

JimPerry

Senior Member
I looked at post #11 and was so impressed I ordered one - it arrived yesterday (very fast) - thankyou
 

Goeytex

Senior Member
Sorry you feel insulted. Your choice.

But had you provided an accurate schematic (good communication) from the beginning, the problem would likely have been caught by someone very quickly. There are good reasons that we ask for accurate schematics, complete code, etc. One being that it enables folks who spend their personal time helping, to solve problems quickly instead of making wild guesses (as this thread demonstrates).

If you want to speak your mind, feel free. I do read my private posts.
 
Last edited:
Top