function "pulsin"

yunie68

New Member
Hi,
I use a pic 16f88, I have a signal in input 6 and input 7,
I need to count how long the signal is on "high level". I alredy ask someone to help me on this forum and he told me to use the pulsin function, my problem is that when I write :
Code:
pulsin 6,1,w1
It doesn't work, I think that picaxe knows "6" as an output and not an input.
If I write "pin6" it's doesn't work either :(

I think it's the only problem on my program because when I replace w1 by a value (let w1=1), the program works..

Please help me to know how to make picaxe understand that "6" is an input and not an output.

I'm sorry if you don't understand this message, my english is bad because i'm a french student.. :( But thank you to read it !
 

alband

Senior Member
Hi,

In what way does it not work? Does the program download onto the pic16f88?

What is you full code? If the code you posted is all you are using, try this code:

Code:
main:     pulsin 6,1,w0
debug
goto main
What software are you using? If you are using "Programming Editor" make sure you have the latest version of it, and also make sure that "PICAXE18X" is checked in the "options" box.
:)
 

yunie68

New Member
Hi,
Yes, the program download onto the pic.
It doesn't work because the w1 value doesn't change.
In my program I have to compare two values, one of those value (w2) is fix(1.5) and w1 should change (I make it change with the signal).
here is my full program :

Code:
main:
let w2=3/2
pulsin 6,1,w1
if w1>w2 then sup
if w1<w2 then sub
pulsin 7,1,w1
if w1>w2 then sup
if w1<w2 then sub
goto main

sup:
high 4
low 5
goto main

sub:
high 5
low 4
goto main
On output 4 and 5 there are DEL (or LED in french) So if w1 is bigger than w2 the del on output 4 should shine, if w1 is lesser than w2 the del on output 5 should shine.

It is correct or is there an other problem? :(

(thank you for helping me :))
 

alband

Senior Member
The code is correct except for one thing. Variables cannot store half values (1.5) only whole numbers (0,1,2,3,4). So instead of comparing them to 1.5, double w1, then compare it to 3.

What is generating the pulse? A pulse that would make w1 < 1.5 would be 10us long. Is that the size of pulse you expect?
 

yunie68

New Member
the probleme is that in the final program I have to put the w1 value on an output with the poulsout function so I can't change it or else i will have to divide it after..
The pulse is generated by an electronic card, the program that I have to make is for a school project, I have a card to realize too.

And I don't expect any value for the pulse I just want to compare it with a fixed value.
 

alband

Senior Member
The value you are comparing it to is equivalent to 10 micro seconds (0.00001 seconds).
Are you sure the card is giving a pulse? Try connecting and LED to the output of the card-reader and see if it flashes.
 

BeanieBots

Moderator
You can use 'setfreq m8' to get 5uS resolution on the 18X but at this stage, that is not your problem.
It sounds like you are neither not seeing the pulses at all or they might be negative going instead of positive going.

As suggested by Alband, first thing is to determine if the pulses are there and being seen. If no oscilloscope is available, the LED idea is a good one.
 

yunie68

New Member
I have an oscilloscope and there are pulses I use my oscilloscope to change the lengh of the pulse and it should change wich led flash.
I think the probleme come from this line :
Code:
pulsin 6,1,w1
I think that "6" define an output for picaxe or I need the input 6 :(
 

hippy

Ex-Staff (retired)
PULSIN 6,1,w1 will read input pin 6, that is not the problem.

When you look at the oscilloscope, how long are these pulses ?

Try a simpler program ...

Do
Do : PulsIn 6,1,w1 : Loop Until w1 <> 0
SerTxd(#w1,CR,LF)
Loop

Using the Terminal function of Programming Editor do you get any output, and if so what values do you see ?
 
Top