Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

pulsein and pulseout simultanously

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive
View previous topic :: View next topic  
Author Message
naseerak

Bascom Member



Joined: 08 Nov 2008
Posts: 138

pakistan.gif
PostPosted: Sun May 09, 2010 8:51 pm    Post subject: pulsein and pulseout simultanously Reply with quote

Hi
Is it possible for atmega32 running at 4MHZ to pulseout a pulse and measure this pulse on the other pin using pulsein. According to my little knowledge it does not seem to be possible using this method but could be possible using Timers which I am not conversant with. There should be a way out but I need a helping hand here with a practical example.
Regards and thanks to the Forum members.
NaseerAk
Back to top
View user's profile
naseerak

Bascom Member



Joined: 08 Nov 2008
Posts: 138

pakistan.gif
PostPosted: Mon May 10, 2010 7:04 pm    Post subject: pulsein and pulseout simultanously Reply with quote

Any One Here
Back to top
View user's profile
AdrianJ

Bascom Expert



Joined: 16 Jan 2006
Posts: 2483
Location: Queensland

australia.gif
PostPosted: Tue May 11, 2010 12:11 am    Post subject: Reply with quote

Yes, we are here, but you ask a question which no-one wants to answer.

While its probably possible to get Pulsein and Pulseout to work together, by rewriting one of them, it may be very difficult, certainly beyond just showing a few lines of code. If you studied the examples of using a timer, and read all the details on timers and compares in the Atmel datasheet for the processor you use, you might be able to see how to do this.

A similar question is in this thread:
http://www.mcselec.com/index2.php?option=com_forum&Itemid=59&page=viewtopic&p=41709#41709

Also with no direct answer, except a couple of suggestions from me.

You should consider that if you generate a pulse, you ( and the processor ) already know what the pulse length is, so why try to measure it with the same processor ?

If you just want to know if a pulse is there - eg if a line is connected, then that is very simple, and does not need Pulsein and Pulseout. Just drive a line high, and see if the pin connected to it is high. ( with suitable electrical connections, of course).

_________________
Adrian Jansen
Computer language is a framework for creativity
Back to top
View user's profile Visit poster's website
naseerak

Bascom Member



Joined: 08 Nov 2008
Posts: 138

pakistan.gif
PostPosted: Thu May 13, 2010 3:32 pm    Post subject: Reply with quote

Thanks Adrian
you were the man who kick started my basic understanding of Basic (bascom). A question usually carries the ???? in the mind of a programmer (here) A questioner does not know the protocol of the questioning and here is the same case with me. The story is as follows.
The PULSEOUT will trigger a solenoid at the rate of 40Ms the solenoid will break a light connection falling on a photo transistor. the solenoid is supposed to be opened in 7-10Ms. if it takes longer then the solenoid is supposed to be wear out. Here I want to measure the opening time of the solenoid. Hopefully My question has become decent Now.
Regards And thanks to Adrian for sparing Time.
Back to top
View user's profile
glena

Bascom Member



Joined: 25 Jul 2007
Posts: 284
Location: PA near Philly

usa.gif
PostPosted: Thu May 13, 2010 4:22 pm    Post subject: Reply with quote

naseerak,

If I'm understanding your question correctly then you could probably do something like the following.

Note this is not tested and may need some changes to work properly!

First, assuming a clock rate of 4MHz

Code:
dim SolinoidTripFlag as byte
dim SolinoidTripTime as word

Config Timer1 = Timer , Prescale = 8    ' This will give you 0.000002 (2us) steps.

SolinoidControl alias portx.y  ' the port that controls the solinoid
SolinoidStatus  alias portx.y  ' the port that shows the actual status of the solinoid

Const Timeout = 20000   ' 40ms / 2us = 20000


''' The process starts here...
SolinoidTripFlag = 0    ' reset the flag
timer1 = 0                 ' clear timer1
SolinoidControl= 1      ' trigger the solinoid
do
        if SolinoidTripFlag  = 0 and SolinoidStatus = 1 then
                SolinoidTripTime  = timer1
                SolinoidTripFlag  = 1
        endif  
while timer1 < TimeOut                  ' wait until we hit the 40ms mark...
SolinoidControl = 0     ' trigger the solinoid

if SolinoidTripFlag  = 1 then
    SolinoidTripTime= SolinoidTripTime * 2     
else
   ' !!! it never tripped!!!
endif

' now SolinoidTripTime has the number of us it took to trip.


I hope this helps!

-Glen

_________________
http://bahbots.com


Last edited by glena on Fri May 21, 2010 2:41 am; edited 1 time in total
Back to top
View user's profile AIM Address
naseerak

Bascom Member



Joined: 08 Nov 2008
Posts: 138

pakistan.gif
PostPosted: Fri May 14, 2010 10:56 am    Post subject: Reply with quote

Thanks Glena
I am trying to understand your code and will give it a try.
Back to top
View user's profile
glena

Bascom Member



Joined: 25 Jul 2007
Posts: 284
Location: PA near Philly

usa.gif
PostPosted: Mon May 17, 2010 4:09 pm    Post subject: Reply with quote

naseerak,

I was just looking at my code again and noticed an error.

In the do loop the lines with:

SolinoidStatusFlag =

should be:

SolinoidTripFlag =

Also note that you need to setup the status port as in input port and the solinoid control port as output.

I hope this helps.

-Glen

_________________
http://bahbots.com
Back to top
View user's profile AIM Address
naseerak

Bascom Member



Joined: 08 Nov 2008
Posts: 138

pakistan.gif
PostPosted: Tue May 18, 2010 7:48 pm    Post subject: Reply with quote

Thanks to every body helping here.
I have omitted the pulseout and doing like this but the resulting pulse is 250ms long while looking on a tektronics 100mhz dso.

Pulsein Pulse , Pinb , 1 , 1

If Seconds > 0 Then
T = Seconds ' to latch the result on the LCD
End If

If Enter = 1 Then
Set Portc.0
Start Timer1
End If
If Count = 20000 Then
Stop Timer1

Reset Portc.0
Timer1 = 0
Count = 0
Enter = 0
End If
I am using count as a variable to show the result on the LCD.
the pulse is supposed to be 40ms as glena calculated earlier.
Back to top
View user's profile
AdrianJ

Bascom Expert



Joined: 16 Jan 2006
Posts: 2483
Location: Queensland

australia.gif
PostPosted: Tue May 18, 2010 10:59 pm    Post subject: Reply with quote

The line
Timeout alias 20000
should be changed to
Const Timeout = 20000
Assuming you still use the name Timeout in your code.

Also have you set the fuses on the processor you use to run at 4 Mhz ?

It really helps to show all of your code, including the $regfile and other directives at the top of your code, so we know exactly how you have the processor and compiler set up.

_________________
Adrian Jansen
Computer language is a framework for creativity
Back to top
View user's profile Visit poster's website
naseerak

Bascom Member



Joined: 08 Nov 2008
Posts: 138

pakistan.gif
PostPosted: Wed May 19, 2010 2:16 pm    Post subject: Reply with quote

$regfile = "m32def.dat"
$crystal = 4000000
$baud = 19200
$hwstack = 128
$swstack = 24
$framesize = 128

Locate 1 , 1
Lcd " TIME = " ; T

Const Timeout = 20000 = Here I am using directly the 20000 figure so I think I dont need the any alies.
Back to top
View user's profile
AdrianJ

Bascom Expert



Joined: 16 Jan 2006
Posts: 2483
Location: Queensland

australia.gif
PostPosted: Wed May 19, 2010 10:53 pm    Post subject: Reply with quote

Ok, so you have told the compiler that you run at 4 MHz, with the $crystal statement. And your timer count of 20000 is set up based on that too.

But have you set the fuses on the processor to actually run at that speed ? By default, the processor will run on the internal clock at 1 MHz, unless you set it otherwise. This may well be the source of the timing error you see.

_________________
Adrian Jansen
Computer language is a framework for creativity
Back to top
View user's profile Visit poster's website
naseerak

Bascom Member



Joined: 08 Nov 2008
Posts: 138

pakistan.gif
PostPosted: Thu May 20, 2010 7:45 am    Post subject: Reply with quote

Ok
My Fuses are
L=FD, H=DF
Back to top
View user's profile
glena

Bascom Member



Joined: 25 Jul 2007
Posts: 284
Location: PA near Philly

usa.gif
PostPosted: Thu May 20, 2010 3:26 pm    Post subject: Reply with quote

naseerak,

Do you have a DSO or someway to measure the pulse that is being sent out in order to confirm its 40ms long or to make sure your getting a pulse at all? If you are and its 40ms then your probably setup correctly with the fuse bits. If not then there is an issue with ether the fuse bits or the code is wrong.

-Glen

_________________
http://bahbots.com


Last edited by glena on Fri May 21, 2010 2:37 am; edited 1 time in total
Back to top
View user's profile AIM Address
AdrianJ

Bascom Expert



Joined: 16 Jan 2006
Posts: 2483
Location: Queensland

australia.gif
PostPosted: Thu May 20, 2010 11:31 pm    Post subject: Reply with quote

I agree with glena, there must be something wrong. My approach when debugging timing issues is first to write some really simple program and see if the timing is what I expect. Can be *really* simple:

Code:

$crystal = 4000000
config portx.y=output
do
set portx.y
waitms 1
reset portx.y
waitms 1
loop
 

Should output a 1msec high and low on the line. If its out by more than a few uSec, your fuses are wrong, or the crystal is not what you think it is.

_________________
Adrian Jansen
Computer language is a framework for creativity
Back to top
View user's profile Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum