how can i toggle an output as long as an input pin is pulsing at a lower rate?


Closed Thread
Results 1 to 2 of 2
  1. #1
    EDWARD's Avatar
    EDWARD Guest

    Default how can i toggle an output as long as an input pin is pulsing at a lower rate?

    I am tring to run a chunk of code over and over as long as the portb.0 input pin is toggling from low to high. here my code i need to continuosly cycle as long as portb.0 is toggling at least 1 per 100 miliseconds, but i cant have a 100 ms pause in th cycling chunk f code below.

    "while portb.0 is toggling atleast 1/100ms then"<-main idea, not actual code

    for x = 1 to 10 + D '<----here
    PULSOUT portc.2,50 '
    next '

    pause T '<----to here

    "wend" <- not actual code


    i need something similar to the COUNT command but doesnt pause while taking its readings

    this is the same pcb ive been working on. i have a solenoid on portc.2. it has to be controlled a really strange way but it works just fine 100% good. you can think the the 3 line, FOR..NEXT statement as the equivilent of HIGH portc.2. then there is the pause command which holds portc.2 low for a specified amount of time. the solenoid is turning on and off repeatedly. i need this 4 line chunk of code to run while portb.0 is going low to high to low to high..etc. this wouldnt be so hard if the input was faster then the out put, in my mind at least.

  2. #2
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default

    EDWARD, This is one way to do what you need too:

    loop:
    if portb.0 <> state then 'reset counter whenever state changes
    state = portb.0
    cntr = 0
    endif
    cntr = cntr + 1
    if cntr < 2000 then 'set for number of pass thru your output loop

    for x = 1 to 10 + D '<----here
    PULSOUT portc.2,50 '
    next '

    pause T '<----to here

    else
    'do something else
    endif

    goto loop

    HTH,
    Dave Purola,
    N8NTA

Similar Threads

  1. LCD will not start
    By btaylor in forum mel PIC BASIC Pro
    Replies: 49
    Last Post: - 24th May 2007, 02:30
  2. Microcontroller with 2 way paging application problem
    By oneohthree in forum mel PIC BASIC Pro
    Replies: 30
    Last Post: - 20th April 2007, 17:27
  3. Timing input pulses and re-outputting them
    By jamie_s in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 28th February 2007, 01:50
  4. Serious Serial Situation Setbacks...
    By Dansdog in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 7th February 2007, 03:46
  5. Using LEDs as light sensors
    By skimask in forum Code Examples
    Replies: 3
    Last Post: - 30th December 2006, 22:19

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts