What am I doing wrong with pin 4?

Hello, this is my first post so please be gentle.

I have a circuit using an 08M on an external beam, when the beam is broken it bleeps in the house in the day time, at night bleeps and brings the lights on.

Below is my program, don't laugh, well not too loud.

On the programming simulator the program works correctly, in real life it does not.

I/P 4 is the analogue input for the lights on timer. After much head scratching I found out that if the I/P on 4 is at minimum up to 1/3rd it works fine, when turned up beyond and all the way to max the inputs stop working. It appears that I/P 4 is still acting as a digital input, when 4=0 the board works, when 4=1 both inputs stop working and the units sits there like a lemon, the light timing function still works correctly.

The first program only had two trigger states, buzzer or buzzer and lights.

To get round this problem I have changed my trigger inputs to include I/P 4 in the table in both states 0 or 1. Originally I/P 4 was not in the table as I thought it being analogue would not change anything. If some kind soul could show me the error of my ways I would be most grateful.

Code:
let dirs = %00010	; sets as outputs 0&1 as 0 is op any way
let pins = %10	; outputs 0 low op 1 high 

main:                    ; input (3) Buzz only. Input (3) & (2) LDR to start lighttime and buzz
readadc 4,b2          ;AD4 is the analogue input to B2 variable for time on

pause 200 	; debounce delay

if pins = %11110 then gosub interrupt   ; night time, (3)beam & (2)LDR high     THESE ARE THE COMMANDS I USE TO GET ROUND PIN 4
if pins = %01110 then gosub interrupt    ; night tine, (3) beam & (2)LDR high
if pins = %11010 then gosub buzzertime  ; daytime (3)beam high (2) LDR low
if pins = %01010 then gosub buzzertime  ; daytime (3)beam high (2) LDR low
goto main
    
   
interrupt:		; Darkness. buzzer(0) and light (1) on    
let pins = %01	; light on and buzzer on
pause 1000	; on for 1 second   
let pins = %00	; buzzer off
pause 1000	; wait 1 second off 
let pins = %01	; buzzer on
pause 1000 	; buzzer on for 1 second
let pins = %00	; buzzer off light stays on  
wait 10  		; 10 second time with light on and no buzz, for beam blocked
for b0 = 1 to b2	; b2 = variable, light on
let b1 = pins & %01100	; b1 is the variable mask,for interrupt, input 3 & 2 high together
if b1 = %01100 then interrupt ; so if (3) beam & (2) LDR are on then buzz and start time loop again
pause 1000	; length of delay for loop 
next b0		; loop command keep counting
let pins = %10	; turns off, 
setint %01100,%01100	; reset interrupt on pin 3 & 2 going high
return		; go to main 

 
buzzertime:	; Daytime. if (3) beam high (2) LDR low then buzz (0)only 
let pins = %11	; buzzer on
pause 1000	; on for 1 second    
let pins = %10	; buzzer off
pause 1000	; wait 1 second off
let pins = %11	; buzzer on
pause 1000 	; buzzer on for 1 second
let pins = %10	; buzzer off


Pause 5000	; delay if beam blocked
return		; go to main 

;0= OUTPUT for buzzer + in alarm
;1= OUTPUT for lights relay + normal state, low for lights on
;2= INPUT from LDR. Switch 0v with 100k to +
;3= Input from Beam. NC switch 0v with 10k to +
;4= Input from potentiometer. 250k
Thank you in advance. I have read the manuals over and over but can not find the answer
 

jtcurneal

Senior Member
I believe that 250 K is to high for your pot. You may have better results with a lower value ( 10k ) pot.

Joel
 

jtcurneal

Senior Member
The current is so low through a 250k pot that the cap in the picaxe does not have time to charge up in the time allowed.
This can give you very erratic ADC readings.

Joel
 

PaulRB

Senior Member
Hi Mark,

Will try to help if I can.

Joel may be right about your 250K pot, I don't know, but I don't think that's your problem anyway, at least not at this stage.

I'm certain your guess is right - input 4 is being read as a digital value. When you use the "pins" command like that, the Picaxe is forced into reading it as either a 0 or 1, so lower pot settings come out as 0 and higher ones come out as 1. Its only when you use the "readadc" command that the Picaxe will measure the input level more accurately and give a number between 0 and 255 as the result.

Am I right in guessing you don't have an actual LDR in the circuit yet? When you do, you will get the same problem if you read the pin its connected to with "pins" - it will read as a 0 or 1 rather than a number, and there's no guarantee that 0 will mean night and 1 will mean day. A cloud passing in front of the sun could cause it to read as night!

I also feel that using the "pins" command like that is making your code very difficult to read and understand, at least for me! My suggestion would be to read each of the inputs, and set each of the outputs with individual commands and set up some meaningful symbols to represent them. For example:

Code:
symbol BUZZER = 0 
symbol LIGHTS = 1
symbol LDR = 2
symbol BEAM = pin3
symbol LIGHTSONTIME = 4
and some symbols to represent the values themselves, like:

Code:
symbol BEAMBROKEN = 0
symbol DUSK = 50
Then you can read or test an input with a command like:

Code:
if BEAM = BEAMBROKEN Then ....

readadc LIGHTSONTIME, b1

readadc LDR, b2
if b2 < DUSK then ...
And switch the outputs on or off with commands like:

Code:
low LIGHTS ; switch lights on
high LIGHTS ; switch lights off

low BUZZER ; switch on buzzer
high BUZZER ; switch off buzzer
Another confusing thing is what you are doing with the setinterrupt command? You have a label called interrupt, but you seem to be using the gosub command to call it also?

And that comment about debouncing - is that because you currently have a switch in place of the LDR you are going to put in later?

Sorry about all the questions! Please don't feel I'm being too critical, just trying to get my head around your circuit design by reading the code!

Paul
 
Oh Paul my inadequices are now more obvious than ever.

This is not a project it is a working device that has been on my outbuildings since christmas, working like a swiss watch. I only had my lights on for about a minute so never encountered the problem.

The system uses a 12 and 5 volt power supply for the beams and the Picaxe, an 08 motor drive board that I modified to give me 3 inputs and 2 outputs, a 5 volt relay, a NORPS 12 LDR, 250K pot and 12 volt piezo sounders that work lovely on 5 volts.

The LDR value of 100k took a little bit of testing to get the right value but provides rock solid night time switch over at dusk.

I have experienced no problems with the LDR in either state.

The only reason this problem reared its head is a friend of mine, a plumber, had looked with jealous eyes at my system working, now I need some plumbing work doing it seemed a fair swop. He needs a longer lights on time to get out of his van and in the house so this is why the problem started.

The system worked fine for a few days then locked up, I took the Picaxe out of my own system down to his house then in my fiddling found the fault caused by pin 4 the pot being turned up above a 1/3 ish.

I taught myself the language ((ha!) half assed is an art not a style) at Christmas as I was given a CEBEK board for a gift, then went on to make the panel, which I was really pleased with.

I will try this weekend to rewrite the program using your terms, which I see are much clearer. I am ignorant so do not understand the points about the interupt.

What I could not understand was PIN 4 operating analogue and digitally. This is the only glitch I have come across apart from the initial interferance problems addressed with some ferrite beads and releasing the relay to bring the lights on rather than powering it.

Is it unnecessary to state the inputs and outputs?
I used the % and binary as that made things quick easy for me to understand.

Thank you very much for the great deal of time and effort you have given me for what is a very simple project.

I have not used symbols before but that is about to change.

Best regards

Mark
 

jtcurneal

Senior Member
As I understand what you are doing, you are using the ADC input from the pot to control the time that the light is kept on.
In the setup that you have been using since last Christmas, you were only using reading from the pot when it was only at
the low end of the rotation. Did you ever check that setup for longer ON times for the lights?

Is the new setup using a new pot or one that has been around for a while?
Older pots may have a buildup on the resistive track from some air born contaminates.

Is the new pot the same taper ( linear taper or log (audio) taper) as the other pot.

I still think that you would have better results using a pot that has a lot less resistance than your 250k.

According to the Microchip 12F683 PIC ( the one used in the Picaxe 08m) "The maximum recommended impedance for analog
sources is 10 k&#937;" (in simple terms, Impedance is a complex form of resistance).

Joel
 
Hi Joel

You are right I only used the low end of the pot. Once I investigated the upper end of the scale problems beset me. I will change the pot for a 10K unit.

I did not know 10K was the scale for an analogue i/p. Thank you for your help

Mark
 

westaust55

Moderator
As some further clarification for PICAXE inputs.

When you have an analogue input signal such as from a pot or LDR,

1. the READADC command will read a voltage and give a return value into the associated variable corresponding to the analogue voltage.

2. a digital input command such as LET b2 = pins can only provide a 0 or 1 state but there is also an indeterminate voltage region which is not reliable.

The following will give you a guide as to the voltage levels for a genuine Low and High states:

LOW states for different digital logic types:

If input <= ~ 0.15*Vdd and Vdd = 3 V then a TTL Low state
If input <= 0.8V at 4.5/5V then TTL Low state (plus ST plus CMOS)
If input <= ~ 0.20*Vdd then a Schmitt Trigger Low state plus CMOS low state
If input <= ~ 0.266*Vdd then only a CMOS Low state

Indeterminate state - depending upon digital logic type,
from the above indicated LOW state to the below indicated HIGH state

HIGH states for different digital logic types:
If input > ~ 0.25*Vdd+0.8V and Vdd = 3 V then TTL High state
If input > 2.0 V at 4.5/5V then TTL High State
If input > ~ 0.733*Vdd then also a CMOS High state (plus TTL high)
If input > ~ 0.8*Vdd then also a Schmitt Trigger High (plus TTL and CMOS high)

PICAXE chips have some inputs that are TTL and some that are ST type.
Have a look at this information by hippy which indicates PICAXE input pin types (currently for all but the latest 08M2/14M2/20M2)
 
Top