Why is output going LOW by itself / How does PINS work

Dave E

Senior Member
Hi all.
Happy New Year!

I was wondering if someone could shed a little light on the PINS command.

I am running a 14M with a few LEDs among other things. I want to be able to control 3 LEDs at the same time and have one LED that gets controlled at different times.
I thought I could use LET PINS=%1110 or some combination of this to control LEDs on outputs 1-3 and then just use HIGH and LOW when needed to control an LED on output 4. However, this didn't work. The LED on output 4 would not stay on when HIGH 4 was issued. So I then ran this test program:

DO
LET PINS = %0100
PAUSE 100
LET PINS = %10000
PAUSE 100
LOOP

What I thought this program should do was the LED on output 2 would blink on and off and the LED on output 4 would come on after the first PAUSE statement then stay on because there was no statement telling output 4 to go LOW.

What this program actually did was alternately blink the 2 LEDs.

So the question is:
Why does output 4 go LOW in the program above?

As always, any input would be appreciated.

Dave E
 

westaust55

Moderator
How does PINS work

The output is not “going low by itself”. You code is making it turn off.

For The LET PINS statement, it is always working with an 8 bit variable so leading bits are treated as zero.

Thus LET PINS = %0100 is the same as %00000100
And LET PINS = %10000 is the same as %00010000

As the 14M only has 6 outputs (0 to 5) the two most significant bits (the two left most bits) are discarded.

Does this do what you were after?
Code:
LET PINS = %00100
PAUSE 100
DO
   LET PINS = %10000
   PAUSE 100
   LET PINS = %10100
   PAUSE 100
LOOP
 

Dave E

Senior Member
Thanks for the reply. I kind of figured that was how it worked.

So it looks like the only way one can make use of the PINS command for the control of outputs is if the programmer will know the exact state of the outputs at all times.

I needed one output to go high and stay high if a condition is met. The PINS command in my program will run once per program cycle so if the one output goes high, it will then be reset to low on the next program cycle.

Dave E
 

westaust55

Moderator
Not impossible to overcome. Without knowing exactly what your (intended) code looks like you could try something like this.

Lets say you have a variable b0 which has the data for the three LED’s that you wish to control

Then to turn OFF the 4th LED you would use:
b1 = b0 AND %00001111 ; or b1 = b0 AND 15
LET PINS = b1

And when you wish to turn ON the 4th LED you could use:
b1 = b0 OR %00010000 ; b1 = b0 OR 16
LETS PINS = b1

bit hard to be very clear in an example without knowing exactly when your code is changing the PINS assignment.

Use of an IF...THEN ... ELSE .... ENDIF construct could help
Code:
IF LED4 = OFF THEN
   b1 = b0 AND %00001111 
ELSE ; if LED4 is to be ON
  b1 = b0 OR %00010000  
ENDIF
LET PINS = b1
 
Last edited:

Dave E

Senior Member
Thanks again for your input, West.
Your suggestion will work in my program if there is room in the 14M. I would need to use your code snipet in several places.
My challange is in making a PWM mosfet controlled battery charger and I want to know what is going on so I have 4 LEDs displaying various "where am I in the program" / "what's going on" / "am I asleep" modes.

Dave E
 

Dave E

Senior Member
I am charging a couple of 7AH AGM batteries from an old 5 watt solar panel. I have the 14M running a P-channel mosfet with PWMOUT. A button is used to select either 13.6 or 14.4 volts. Indicators show if PWM is increasing or decreasing and if PWM is at a max or min. It checks every once and a while to see if the charge voltage is still there or not. If not, it goes to sleep and indicated that it is sleeping.
Part of the challenge was to use only 256 bytes. Once I get it where I want it, I will see if I can get an 08M to run it.

Dave E
 

premelec

Senior Member
BB - I wonder if you tried any PWMOUT strategies in your MPPT quest such as a rough set then modulated by PWMOUT - or burst mode - I would think it's how fast you want to make the correction that is the main thing and if you could stand to correct within .1 seconds that might be close enough for many purposes [like battery charge from PV].
 

BeanieBots

Moderator
Premelec,
I'm not 100% sure what you are suggesting.
Bear in mind, I am very specifically describing the issue about using PWMout to drive the FET and NOT using PWMout to control for example a demand value.

Making rapid adjustments is not an option because the PWM counter is reset each time PWMout is adjusted. This might be worth investigating using the PWMduty command, only available on the 28X1 but unfortunatley not on the 18X.

Even with rapid adjustments, I would not be sure how to apply such an algorythm in practice. The entire loop response would have to be taken into account for it to work. That would result in the SMS input and output caps becoming critical values and the system load would have to be constant.

Maybe with a lot of perseverance it might be possible to include something like a pulsout command just before the PWMout update which could be fine tuned to include a "pause" in the PWM stream. That would work in theory but implementing actual code which could cope with issues such as a "carry" from an adjustment on the pause to an adjustment on the PWM is more effort than I am prepared to put in compared to an analogue solution using PWMout to adjust the "demand" over a finer range.

To describe the problem in mechanical terms, it's a bit like trying to use an 8bit position value to control the clutch on a car to hold the car on a hill. The position range is fixed at the full distance of the clutch pedal travel but the required position requires very fine control over a very small range of travel.
Oscillating the clutch around the bite point would work but again, how to do that in practice is another story.
 

premelec

Senior Member
Thanks BB for additional info - I was thinking that the PWMOUT was just too coarse and one could do something like the dual potentiometers we used to see which had R and 10R on the same shaft with slop to the 10R rotor so you could do fine and coarse with one shaft... :)
I guess that dates me [also mainly analog design] - the electronic equivalent being something like getting close to where you want to go with a digital pot [or whatever] and then doing finer adjustment with the PWMOUT.

However you indicate that there is a big anomaly in the PWMOUT as it resets when the value is changed. I need to look at that with a scope and see what that anomaly looks like. I was thinking that some integration of the PWMOUT over, say, .1 second could deal with quite a bit - indeed perhaps the anomaly would be 'included' in the ultimate analog control signal to a MOSFET or switching IC regulator in a way that it wouldn't interfere.

It would be good to have the reset anomaly chronicled in the manual with some data on how long the reset takes and if the output goes high or low or off or random during the reset!

I am hoping that a simple MPPT [roughly] could be made with a PICAXE 08M... The data you've discovered in your quest is very helpful for my thinking about this.
 

BeanieBots

Moderator
You've slightly missed the point. (of my Pb charger post).
If you use PWM to control the demand of a switcher IC, then all is well.
It's using PWM to drive the FET that gives rise to the 'courseness' problem.

Please take this to the project thread if you want to know more.
 
Top