PDA

View Full Version : I don't understand this program



Russ Kincaid
- 14th June 2006, 23:51
REM TEST 3
REM 16F627A
PORTA =0
TRISA = %00010000
TRISB = %00111111

LOOP:
HIGH PORTB.6
PAUSE 1000
HIGH PORTB.7
PAUSE 100

LOW PORTB.6 'DOES NOT GO LOW!
LOW PORTB.7
PAUSE 1 ' WHY DO I NEED THIS PAUSE STATEMENT? WITHOUT IT,
'PORTB.6 NEVER GOES LOW. WITH IT, PORTB.6 IS
'LOW ONLY 1 mS.
LOW PORTB.6 'DOES NOT STAY LOW
GOTO LOOP
END

paul borgmeier
- 15th June 2006, 00:22
Russ,

I am not sure what you are trying to do. Without an OScope, you probably cannot see what your program is doing because it is doing it so fast.


PAUSE 1 ' WHY DO I NEED THIS PAUSE STATEMENT? WITHOUT IT,
'PORTB.6 NEVER GOES LOW. WITH IT, PORTB.6 IS
'LOW ONLY 1 mS

It will and does go low with or without your Pause statement. Without the Pause, RB6 is low only for a few uS, which is hard to detect. Your program is humming along at 1,000,000 instructions per second. You make RB6 low with line 5 and then immediately make it high again with line 1) with only a few instruction in between. With the pause of 1 (= 1000uS) inlcuded on line 7, you basically get a 1mS off time before you turn it back on with line 1. Clear as mud?

For reference

LOOP:
1) HIGH PORTB.6
2) PAUSE 1000
3) HIGH PORTB.7
4) PAUSE 100

5) LOW PORTB.6 'DOES NOT GO LOW!
6) LOW PORTB.7
7) PAUSE 1 ' WHY DO I NEED THIS PAUSE STATEMENT? WITHOUT IT,
'PORTB.6 NEVER GOES LOW. WITH IT, PORTB.6 IS
'LOW ONLY 1 mS.
8) LOW PORTB.6 'DOES NOT STAY LOW
9) GOTO LOOP

Paul Borgmeier
Salt Lake City, Utah
USA

Russ Kincaid
- 15th June 2006, 02:21
Oh, thanks. I am glad you can't see my red face!

malc-c
- 15th June 2006, 09:44
Russ,

Try an experiment with the delay timing.

1) HIGH PORTB.6
2) PAUSE 1000
3) HIGH PORTB.7
4) PAUSE 1000

5) LOW PORTB.7
6) LOW PORTB.6
7) pause 1000
8) GOTO LOOP

I've not tested this, but logic states that PORTB.6 goes high, waits a second, then PORTB.7 will go high, waits a second then both PORTB.6 & 7 goes low, waits a second then loops round.

It will prove the the program is actually turning on and off the ports, and then you can play with the timing to get the desired effect you're after. As Paul stated, unless you have really keen eyesight, 1ms is very hard to see. Blink and you'll miss it ;)

BigWumpus
- 15th June 2006, 19:41
What is connected to PortB.6 ?
Maybe you struggled into the read-modify-write-trouble...

Russ Kincaid
- 15th June 2006, 23:03
Portb.6 connects to a 1K resistor and NPN base. My original post was a logical error, the basic problem that I was trying to solve, was that portb.6 was not producing an output sometimes. It turned out that the 5 volt supply was sagging after 4 seconds causing brownout reset. I was confused by the program running so long before failing.