Pin High for 13 seconds while....


Closed Thread
Results 1 to 5 of 5

Hybrid View

  1. #1
    Chadhammer's Avatar
    Chadhammer Guest

    Default Pin High for 13 seconds while....

    Life cycle tester: I need to hold a pin (Relay1) high for about 10 seconds while I am doing other things with other pins. I want to drive a relay and that runs a Pic outputting a square wave at 20 Hz for 200 pulses. I want to count the pulses using TMR0. Then I need Relay1 to go low for about 3 seconds .

    I have 2 problems right now:

    1) Relay1 pin goes high for a blip then low so I need to get some kind of timing loop going for the relay cycle. But how do i keep other things going on with other pins at the same time?

    2) my test cycle counter goes to 255 and resets and I want it to go to 9999 cycles before going back to 0 and so does my pulse counter.

    Any help or push in the right direction would be great


    Code:
    Init:
               INTCON.7 = 0             'Disable interrupts
               OPTION_REG = %00111000 
               TRISB = %01100111        'Setup Port B
               PORTB = %00000000        'Clear port B pins
               T_cyc Var Byte    
               T_cyc = 0
               PAUSE 1000               'Pause for the LCD to wake
               
    Relay:               
               T_cyc = T_cyc + 1        'Test cycle counter
               Relay1 var PORTB.5
               High Relay1              'Drive relay pin 26 high for 13 seconds
               Goto Main           
    
    Main:      
               MP_Count var PORTB.6     ' Holds count value
               MP_Count = 0             ' Clear pulse counter
               TMR0 = 0                 ' Clear TMR0 counter
               MP_Count = TMR0          ' Get TMR0 count
               
               LCDout $fe, 1, "Test # ",dec4 T_cyc 'Test cycle (0-9999 tests)
               LCDout $fe,$c0, DEC5 MP_Count, " Pulses" 
               
               Low Relay1
               PAUSE 4000
               GOTO Relay                  
          
    End
    Using a Pic 16F870

  2. #2
    Chadhammer's Avatar
    Chadhammer Guest


    Did you find this post helpful? Yes | No

    Default Getting closer

    Udate: I have some success now. I used COUNT[pin,duration,var] and it's working fine except for my tests complete: How do I get my cycle counter to count decimal beyond 255?

    Code:
    Init:
               INTCON.7 = 0             'Disable interrupts
               OPTION_REG = %00111000 
               TRISB = %01100111        'Setup Port B
               PORTB = %00000000        'Clear port B pins
               T_cyc Var Byte    
               T_cyc = 0
               PAUSE 1000               'Pause for the LCD to wake
               Relay1 var PORTB.5
               X Var Byte           
               B VAR Byte
               X=0
               B=0
    
    Relay:               
               T_cyc = T_cyc + 1        'Test cycle counter
               High Relay1              'Drive relay pin 26 high for 10 seconds
               Count PORTB.6,11000,X         
               
               LCDout $fe, 1, "Test # ",dec4 T_cyc 'Test cycle (0-9999 tests)
               LCDout $fe,$c0, DEC5 X, " Pulses"
               
               Low Relay1                'Drive realy pin 26 low 
               PAUSE 1000                'Pause 1 second
               If X=198 then B=B+1       'Did we get 198 pulses (pass or fail)?
               LCDOUT $fe,$c0            'Clear the LCD
               LCDOUT $fe,$c0, DEC4 B, " Tests OK"  'Print the # of good tests
               
               PAUSE 2000
               LCDOUT $fe,$c0
               PAUSE 500 
               GOTO Relay                  
          
    End

  3. #3
    Join Date
    Feb 2004
    Location
    Germany
    Posts
    762


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Chadhammer
    Udate: I have some success now. I used COUNT[pin,duration,var] and it's working fine except for my tests complete: How do I get my cycle counter to count decimal beyond 255?
    Code:
               T_cyc VAR WORD
    regards

    Ralph

    _______________________________________________
    There are only 10 types of people:
    Those who understand binary, and those who don't ...
    _______________________________________________



  4. #4
    Chadhammer's Avatar
    Chadhammer Guest


    Did you find this post helpful? Yes | No

    Default Thank you

    That worked perfectly

  5. #5
    Join Date
    Feb 2004
    Location
    Germany
    Posts
    762


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Chadhammer
    That worked perfectly
    My pleasure.
    regards

    Ralph

    _______________________________________________
    There are only 10 types of people:
    Those who understand binary, and those who don't ...
    _______________________________________________



Similar Threads

  1. SERIN MIDI out of Synch?
    By jncortes in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 9th June 2009, 20:08
  2. Old and beyond help ?
    By DavidFMarks in forum mel PIC BASIC Pro
    Replies: 46
    Last Post: - 11th December 2008, 15:23
  3. Microcontroller with 2 way paging application problem
    By oneohthree in forum mel PIC BASIC Pro
    Replies: 30
    Last Post: - 20th April 2007, 17:27
  4. sample code for M25P32
    By Pedro Santos in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 9th January 2007, 02:37
  5. Another RTC, DS1287
    By DavidK in forum Code Examples
    Replies: 0
    Last Post: - 12th December 2006, 17:07

Members who have read this thread : 0

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