test
clrwdt
clrf TMR0
clrf pulse_count
wait3
movlw d'200'
subwf TMR0, W
btfsc STATUS, C
goto time_up
btfsc GPIO, 3
goto wait3
wait4
movlw d'200'
subwf TMR0, W
btfsc STATUS, C
goto time_up
btfss GPIO, 3
goto wait4
incf pulse_count, F
goto wait3
time_up
movlw d'3'
subwf pulse_count, W
btfss STATUS, C
goto test
movlw d'9'
subwf pulse_count, W
btfsc STATUS, C
goto test
Thanks for getting back to me. What would be the best way to time it?
Could one way be to reset the watchdog timer when both loops have been met, thereby allowing the code to proceed to the "output on" statement?
program charge_pump_controller
' Declarations section
' Header******************************************************
symbol RELAY = PORTB.0 ' Pin PORTD.3 is named RELAY
dim LOWFREQ as byte ' Variable TEST is of byte type
dim HIGHFREQ as byte
main: ' Start of program
LOWFREQ = 90 ' Constant TEST = 5
HIGHFREQ = 180
TRISB = 0
OPTION_REG = 0x0E ' Prescaler is assigned to timer
PORTA = 0 ' Reset PORTA
TRISA = 0xFF ' All portA pins are configured as inputs
PORTB = 0 ' Reset PORTB
'TRISA = %11110111 ' Pin RD3 is configured as an output, while other pins are
' configured as inputs
OPTION_REG.5 = 1 ' Counter TMR0 receives pulses through the RA4 pin
OPTION_REG.3 = 1 ' Prescaler rate is 1:1
TMR0 = 0 ' Reset timer/counter TMR0
while 1
TMR0 = 0
delay_ms(200)
if TMR0 > LOWFREQ then
if TMR0 < HIGHFREQ then
RELAY = 1 ' Numbers match. Set the RD3 bit (output RELAY)
else
RELAY = 0
end if
else
RELAY = 0
end if
wend ' Remain in endless loop
end. ' End of program
program charge_pump_controller
' Declarations section
' Header******************************************************
symbol RELAY = PORTB.0 ' Pin PORTD.3 is named RELAY
dim LOWFREQ as byte ' Variable TEST is of byte type
dim HIGHFREQ as byte
dim COUNTREP as integer
main: ' Start of program
LOWFREQ = 10 ' Constant TEST = 5
HIGHFREQ = 70
TRISB = 0
OPTION_REG = 128 ' Prescaler is assigned to timer WDT (1:64)
PORTA = 0 ' Reset PORTA
TRISA = 0xFF ' All portA pins are configured as inputs
PORTB = 0 ' Reset PORTD
'TRISA = %11110111 ' Pin RD3 is configured as an output, while other pins are
' configured as inputs
OPTION_REG.5 = 1 ' Counter TMR0 receives pulses through the RA4 pin
OPTION_REG.3 = 1 ' Prescaler rate is 1:1
TMR0 = 0 ' Reset timer/counter TMR0
while 1
TMR0 = 0
delay_ms(18)
if TMR0 > LOWFREQ then
if TMR0 < HIGHFREQ then
COUNTREP = COUNTREP + 1
if COUNTREP > 2 then
RELAY = 1 ' Numbers match. Set the RD3 bit (output RELAY)
end if
else
COUNTREP = 0
end if
else
RELAY = 0
COUNTREP = 0
end if
wend ' Remain in endless loop
end. ' End of program
Now I just need to get the code to work for the 12c508. There is one slight problem, Mikrobasic doesn't support the 12c508..... bugger! So I need to take the exported Assembly code and tweak it.
program Charge_Pump_PIC12F675
' Processor speed @ 1MHz
' All additional off (Watchdog off, brownout off, etc)
' Header******************************************************
'GP0 and GP1 cannot be digital outputs
symbol RELAY = GPIO.5 ' Pin GP5 is named RELAY
dim LOWFREQ as byte ' Variable TEST is of byte type
dim HIGHFREQ as byte
dim COUNTREP as boolean
main:
' Main program
ADCON0.0 = 0
ANSEL = 0 ' Turn off Analog to Digital converter GP2
LOWFREQ = 14 ' 3.5KHz switch on
HIGHFREQ = 70 ' 16.3 KHz Switch off
TRISIO = 0 ' Set as output
OPTION_REG = 128 ' Prescaler is assigned to timer WDT (1:64)
TRISIO.2 = 1 ' GP2 pin is configured as input
RELAY = 0 ' Reset Relay Pin
' configured as inputs
OPTION_REG.5 = 1 ' Counter TMR0 receives pulses
OPTION_REG.3 = 1 ' Prescaler rate is 1:1
TMR0 = 0 ' Reset timer/counter TMR0
COUNTREP = false
while 1
TMR0 = 0
delay_ms(18)
if TMR0 > LOWFREQ then
if TMR0 < HIGHFREQ then
if COUNTREP = true then
RELAY = 1 ' Numbers match. Set the RD3 bit (output RELAY)
end if
COUNTREP = true
else
COUNTREP = false
end if
else
RELAY = 0
COUNTREP = false
end if
wend ' Remain in endless loop
end.
Note: The ANSEL (9Fh) and CMCON (19h)
registers (9Fh) must be initialized to
configure an analog channel as a digital
input. Pins configured as analog inputs will
read ‘0’. The ANSEL register is defined for
the PIC12F675.
CMCON = 0x07;
ANSEL = 0x00;
program Charge_Pump_PIC12F675
' Processor speed @ 1MHz
' All additional off (Watchdog off, brownout off, etc)
' Header******************************************************
'GP0 and GP1 cannot be digital outputs
symbol RELAY = GPIO.5 ' Pin GP5 is named RELAY
dim LOWFREQ as byte ' Variable used to store the lower frequency threshold
dim HIGHFREQ as byte ' Variable used to store the higher frequency theshold
dim COUNTREP as boolean ' Used to count two repetitions of successful frequency ranges
main:
' Main program
ADCON0.0 = 0 ' Turn off analog settings
ANSEL = 0 ' Turn off Analog to Digital converter GP2
CMCON = 7 ' Turn off comparators
LOWFREQ = 5 ' 3.5KHz switch on
HIGHFREQ = 29 ' 16.3 KHz Switch off
TRISIO = 0 ' Set as output
OPTION_REG = 128 ' Prescaler is assigned to timer
TRISIO.2 = 1 ' GP2 pin is configured as input
RELAY = 0 ' Reset Relay Pin
OPTION_REG.5 = 1 ' Counter TMR0 receives pulses
OPTION_REG.3 = 0 ' Prescaler rate is 1:1
TMR0 = 0 ' Reset timer/counter TMR0
COUNTREP = false ' Initialise the successful frequency count
while 1
TMR0 = 0
delay_ms(18)
if TMR0 > LOWFREQ then
if TMR0 < HIGHFREQ then
' If there are two successful repetitions, then turn on relay
if COUNTREP = true then
RELAY = 1 ' Numbers match. Set the RD3 bit (output RELAY)
end if
COUNTREP = true
else
' If the frequency exceeds the upper threshold,
' turn off the RELAY and reset the successful frequency count
RELAY = 0
COUNTREP = false
end if
else
' If the frequency is less than the lower frequency threshold, turn off and reset count
RELAY = 0
COUNTREP = false
end if
wend ' Remain in endless loop
end.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?