Hi Nicholas,
Can you post all of your code? It helps to know which pins you have defined,
and how you have things configured.
Hi Nicholas,
Can you post all of your code? It helps to know which pins you have defined,
and how you have things configured.
i agree to see the whole thing.
I find something strange here...
There's something missing... a simple pause after the Low LED.Code:for loop = 1 to 10 ; If the battery voltage is low high led ; Flash the LED 10 times Pause 500 ; at a rate discernable from the low led ; transmit LED flash rate next
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
Here's the whole Code, I tried to use NAP in place of PAUSE and the LED stays on for the alloted time but the blink part does not work. I've also attached a variant to the blink part which also failed to blink the LED.
;************************************************* ********
; Define statements.
define NO_CLRWDT 1 ;Don't insert CLRWDTs
define OSC 20 ;every MPU used is 20mhz
'Port operation configurations
CMCON0 = %00000111 'Port A all digital
VRCON = %00000000 'CVref turned off
OPTION_REG = %10000111 'Disable PORTA pullups, set TMR0 scaler to 1:256
; Program Variables
Loop VAR BYTE ;general loop counter for LED flashing
Outp CON 0
Inp CON 1
'Assign Ports to simple name
LowVoltage VAR PortA.0 'Battery low voltage detection port
ReedSwitchState var PORTA.1 'Reed Switch ON and OFF state line
LED VAR PORTA.2 'Turn LED ON and OFF
HoldTxON VAR PORTC.0 'Hold Tx ON when water contacts activated
Tx_Data VAR PORTC.1 'Transmit Data Line
Tx1_Enable VAR PORTC.2 'Transmit 121.5Mhz Line
Tx2_Enable VAR PORTC.3 'Tranmit 156MHz Line
MotorControl_1 VAR PORTC.4 'Activate Release Mechanism
MotorControl_2 VAR PORTC.5 'Activate Latch Mechanism
'Initialize port states
TrisA.0=Inp 'set batt low voltage detection to input
TrisA.1=Inp 'set Reed switch state to input
TrisA.2=Outp 'set led transmission to output
TrisC.0=Outp 'set Hold Tx Line ON to output
TrisC.1=Outp 'set Transmit data line to output
TrisC.2=Outp 'set Transmit @121.5 to output
TrisC.3=Outp 'set Transmit @156 to output
TrisC.4=Outp 'set Motorcontrol_1 to output
TrisC.5=Outp 'set Motorcontrol_2 to output
'Goto Main
;************************************************* ******************************
Main:
low HoldTxON ; Initialize by clearing all the outputs
low LED
low Tx_Data
Low Tx1_Enable
low Tx2_Enable
Low MotorControl_1
LOW MotorControl_2
GOSUB Lowvoltagecheck
end
;************************************************* ******************************
; Subroutine to check for battery voltage at the beginning and end of
; transmission flashing to signify low voltage or high voltage
LowVoltageCheck:
If lowVoltage = 1 then ; If the battery voltage is OK
high led ; turn on the LED for 5 seconds
pause 5000
LOw LEd
else
for loop = 1 to 10 ; If the battery voltage is low
high led ; Flash the LED 10 times
Pause 500 ; at a rate discernable from the
low led ; transmit LED flash rate
next
endif
return
;************************************************* ********
PS: This is the code I used to try and break up the subroutine further for testing but failed to work also.
;************************************************* ******************************
; Subroutine to check for battery voltage at the beginning and end of
; transmission flashing to signify low voltage or high voltage
LowVoltageCheck:
If lowVoltage = 1 then GoodBattery
if lowvoltage = 0 then LowBattery
LowBattery:
for loop = 1 to 10 ; If the battery voltage is low
gosub Blink
next loop
Blink:
high led ; Flash the LED 10 times
pause 500 ; at a rate discernable from the
low led ; transmit LED flash rate
return
GoodBattery: ; If the battery voltage is OK
high led ; turn on the LED for 5 seconds
pause 5000
LOw LEd
return
;************************************************* ********
Originally Posted by Nicholas
Don't you need another RETURN after the LOWBATTERY blinks?
JDG
I've inserted comments where I added a few things. Let us know if this
version works.
If this "doesn't" work, make sure you have a pull-up on /MCLR to Vcc, at leastCode:;************************************************* ******** ; Define statements. ' Now you know for sure what these are set for @ device pic16F877A, hs_osc, wdt_off, lvp_off, protect_off ' Potential problem below unless you're disabling WDT in config fuse ' (like above) you do not want to use this define. PBP needs to insert ' CLRWDT commands throughout your code to make sure the WDT does ' not cause a device reset define NO_CLRWDT 1 ;Don't insert CLRWDTs define OSC 20 ;every MPU used is 20mhz 'Port operation configurations CMCON0 = %00000111 'Port A all digital VRCON = %00000000 'CVref turned off ' Added this to disable A/D. Now you can use ports A/E for digital I/O ADCON1 = 7 OPTION_REG = %10000111 'Disable PORTA pullups, set TMR0 scaler to 1:256 ; Program Variables Loop VAR BYTE ;general loop counter for LED flashing Outp CON 0 Inp CON 1 'Assign Ports to simple name LowVoltage VAR PortA.0 'Battery low voltage detection port ReedSwitchState var PORTA.1 'Reed Switch ON and OFF state line LED VAR PORTA.2 'Turn LED ON and OFF HoldTxON VAR PORTC.0 'Hold Tx ON when water contacts activated Tx_Data VAR PORTC.1 'Transmit Data Line Tx1_Enable VAR PORTC.2 'Transmit 121.5Mhz Line Tx2_Enable VAR PORTC.3 'Tranmit 156MHz Line MotorControl_1 VAR PORTC.4 'Activate Release Mechanism MotorControl_2 VAR PORTC.5 'Activate Latch Mechanism 'Initialize port states TrisA.0=Inp 'set batt low voltage detection to input TrisA.1=Inp 'set Reed switch state to input TrisA.2=Outp 'set led transmission to output TrisC.0=Outp 'set Hold Tx Line ON to output TrisC.1=Outp 'set Transmit data line to output TrisC.2=Outp 'set Transmit @121.5 to output TrisC.3=Outp 'set Transmit @156 to output TrisC.4=Outp 'set Motorcontrol_1 to output TrisC.5=Outp 'set Motorcontrol_2 to output 'Goto Main ;************************************************* ****************************** Main: low HoldTxON ; Initialize by clearing all the outputs low LED low Tx_Data Low Tx1_Enable low Tx2_Enable Low MotorControl_1 LOW MotorControl_2 GOSUB Lowvoltagecheck ' <-- problem area here. When program flow returns ' from Lowvoltagecheck, it lands on END and the PIC ' enters a continuous sleep loop GOTO Main ' <-- this fixes the problem end ;************************************************* ****************************** ; Subroutine to check for battery voltage at the beginning and end of ; transmission flashing to signify low voltage or high voltage LowVoltageCheck: If lowVoltage = 1 then ; If the battery voltage is OK high led ; turn on the LED for 5 seconds pause 5000 LOw LEd else for loop = 1 to 10 ; If the battery voltage is low high led ; Flash the LED 10 times Pause 500 ; at a rate discernable from the low led ; transmit LED flash rate PAUSE 500 ' <-- added this pause so you can see the LED blink next endif return
a 0.1uF cap between PIC Vcc/GND pins, and a clean/stable power supply.
I finally got it to work through two changes. First I had to remove the CLRWDT define term and I was able to get the LED to blink accordingly. I also had to add the Analog Select Command (ANSEL) to set some of my pins to make the whole program work. Although am not quite clear how that affected my program, the ANSEL changes seemed to make it work.
Thanks for all your assistance.
Nicholas.
Originally Posted by Nicholas
The CLRWDT has tripped me up on a few projects myself, and this was with the WDT disabled, not running, and otherwise not a factor... Somehow it seemed to have something to do with PBP's timing underneath somewhere, don't know where, don't really care. All I know is, if I'm having an under-fixable problem, either adding or removing the CLRWDT define is one of my personal 'troubleshooting' steps.
JDG
Bookmarks