PDA

View Full Version : Pin High for 13 seconds while....



Chadhammer
- 14th June 2005, 21:19
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




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

Chadhammer
- 14th June 2005, 23:47
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?



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

NavMicroSystems
- 15th June 2005, 01:09
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?



T_cyc VAR WORD

Chadhammer
- 15th June 2005, 21:52
That worked perfectly

NavMicroSystems
- 16th June 2005, 00:36
That worked perfectly
My pleasure.