BasicMicro - Forums

www.basicmicro.com
It is currently Mon May 21, 2012 12:51 am

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: am I using pulsin command the right way?
PostPosted: Sun Apr 10, 2011 6:19 pm 
Offline
New User

Joined: Sun Jan 16, 2011 3:36 pm
Posts: 4
I have the basic atom lab board, Item Id: B0262

Still learning all the commands and such, I wanted to do the following, just to see if I could get it to work:

when I press a button, LED should turn on. If this same button is released in less than one second, LED should turn off; however ... if button is held for one second or longer, LED should blink 3 times before doing the shutoff. Had a feeling that pulsin command would help, as it could be for measuring button press times, for which then, the value stored into the variable of pulsin command would determine whether to shut off LED or to blink LED.

This is my attempt, but not sure why it was not working, if anybody can enlighten me a bit, I'd appreciate it, and thanks in advance :D


Code:
input p0   ;button
output p1   ;LED
time_duration var word
main
   high p0
   high p1
   pulsin 0, 0, main, 2000000, time_duration      ;time how long button is pressed
   if time_duration <  2000000 then LEDOff
   if time_duration >= 2000000 then LEDBlink
               
   LEDOff
      low p1
      goto end1
   
   LEDBlink
      low p1
      pause 500
      high p1
      pause 500
      
      low p1
      pause 500
      high p1
      pause 500
         
      low p1
      pause 500
      high p1
      pause 500
      low p1
      
end1            
end


Top
 Profile  
 
 Post subject: Re: am I using pulsin command the right way?
PostPosted: Tue Apr 12, 2011 9:43 am 
Offline
Site Admin
User avatar

Joined: Thu Mar 01, 2001 11:00 am
Posts: 903
Location: Temecula, CA
Problem Code:
First, remove the high p0 command. You are trying to use p0 as an input so setting it to a high output is wrong.

Not necessary code:
Also all pins are inputs on reset so you don't have to do the first input p0 command at all. Same goes for the output p1 command, the high p1 command will make the pin an output and set it high without needing the output p1 command.

Code:
time_duration var word
high p1

pulsin p0, 0, LEDblink, 2000000, time_duration      ;time how long button is pressed, this code will loop back to main if no pulse is detected in 2000000 us
           
LEDOff
   low p1
   end   

LEDBlink
   low p1
   pause 500
   high p1
   pause 500
     
   low p1
   pause 500
   high p1
   pause 500
         
   low p1
   pause 500
   high p1
   pause 500
   low p1
   end


The timeout argument tells pulsin to jump to LEDBlink of no pulse has been received in the specified time. Also, since you are not looping, you don't need the main label at all. You don't need the conditionals in this case since any pulse less than the time would cause the LEDoff code to run and any other pulse or lack of said pulse will cause the code to execute LEDblink.

You may need to change the second argument of pulsin from 0 to 1, depends on how your button is wired up.

_________________
Tech Support
Basic Micro - Robotic Technology Evolved


Top
 Profile  
 
 Post subject: Re: am I using pulsin command the right way?
PostPosted: Tue Apr 12, 2011 10:30 am 
Offline
New User

Joined: Sun Jan 16, 2011 3:36 pm
Posts: 4
The button currently is normally high because of a 10K pullup resistor. Button goes low upon me pressing it.

I think pulsin direction should be 0, as button timer should start checking from high->low transition of the input pulse.


So I'll give the code a try, see if it does what I'd like correctly this time.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 2 guests


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 post attachments in this forum

Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

phpBB SEO