russman613
- 27th February 2006, 15:28
Hey all,
i am still struggling with what seems like eratic behavior with my PIC12F675.
I am trying to build an IR detection array thats smarter than a 555 timer or another hardwired 38500 oscillator and figured the small and tidy footprint of a 12F675 would be ideal.
right now, i am at the stage where i am trying to get IR LED to flash at 38500MHz for about 10ms. it seems to work fine, but when i add some "smarts" code, the whole thing stops working. here is the following code i am adding.
' ... Problem is between here
if (leftcount = duration) then
for i = 1 to 3
high ledsignal
pause 500
low ledsignal
pause 500
next i
low ledsignal
endif
' ... and here
to my mainline, the chip wont start.
the same happens if i add:
freqout gpio.3, 10, 38500
instead of the ASM delay block. I went down the ASM block path because it seems that freqout will not work with the 12F675 though i can't find that explicitly stated anywhere.
Bottom Line Issue:
~~~~~~~~~~~
It seems that when i add code that the chip does not like, it won't even start - the status LED blink i have at the top of my code won't even activate etc - nothing happens.
I am using a USB melabs programmer. i disconnect the USB from my computer between flashes to make sure i don't fry anything. i am using MicroCode studio 2.3.0.0 and PicBasic PRO compiler 2.46.
everyhing is soldered together to eliminate any potential of bad connections. i am using the following parts (http://www.hobbyengineering.com/H1765.html, http://www.hobbyengineering.com/H1992.html) without the 4Mhz resonator installed on the prototype board.
gpio.0 is a regular old red LED with a 220 ohm resistor on it.
gpio.3 is the detect from the IR Receiver (http://www.parallax.com/detail.asp?product_id=350-00014)
gpio.5 is the IR LED out with a 1K resistor (http://www.parallax.com/detail.asp?product_id=350-00017)
i have a .1uf bypass capacitor on the +5v and Ground leads of the detector
any thoughts or suggestions on what i am missing would be appreciated. probably something simple and silly.
it sure is frustrating. with that if block in there, the thing won't even start, i yank it out and it seems to work fine again.
is there a possibility that, since i am using the internal oscillator, i have overwritten some config (calibration) space or something that ensures the internal oscillator runs as it should? This question is nagging at me in the back of my mind.
here is the full code listing:
' Defines that set up the PIC
@ DEVICE pic12F675, INTRC_OSC_NOCLKOUT ' Internal Oscillator
@ DEVICE pic12F675, WDT_ON ' Watchdog Timer
@ DEVICE pic12F675, PWRT_ON ' Power-On Timer
@ DEVICE pic12F675, MCLR_OFF ' Master Clear Options set to Internal
@ DEVICE pic12F675, BOD_ON ' Brown-Out Detect
@ DEVICE pic12F675, PROTECT_OFF ' Code Protect off
@ DEVICE pic12F675, CPD_OFF ' Data EEPROM Protect off
'define xtal 4 ' don't think i need this - cant find it in the .inc
define OSC 4
' Initialise my Registers
TRISIO=%00001000 ' all output except gpio.3 is input
CMCON=%00000111 ' comparator module reg 6-1 page 35. Disable all
ANSEL=%00000000 ' A/D config reg 7-2. Set all pins to digital
'ADCON0=%00000000 ' reg 7-1 not required but shuts off A/D control
pause 1000
' Degine PINs
ledSignal var GPIO.0
leftIRLed var GPIO.5
irDetect var GPIO.3
' Constants
duration con 100
' Variables
i var word ' Genral purpose counter
dur var word
leftCount var word
' Code Mainline
' Blink the status led so we know we're ok.
high ledSignal
pause 2000
low ledSignal
pause 2000
'Mainline loop....
MainLoop:
' Check to see if we have activity on the left LED.
gosub LeftIR
' ... Problem is between here
if (leftcount = duration) then
for i = 1 to 3
high ledsignal
pause 500
low ledsignal
pause 500
next i
low ledsignal
endif
' ... and here
pause 20
Goto MainLoop
End
'******************************
'
' Subroutines ...
'
'******************************
'1/38500 = 0.000026
LeftIR:
leftCount = 0
dur = duration
asm
cycleLeft
BSF GPIO,5 ;1uS Begin HIGH duty cycle
NOP ;2uS each nop is 1uS long
NOP ;3uS
NOP ;4uS
NOP ;5uS
NOP ;6uS
NOP ;7uS
NOP ;8uS
NOP ;9uS
NOP ;10uS
NOP ;11uS
NOP ;12uS
NOP ;13uS
BCF GPIO,5 ;1uS Bigin Low
NOP ;14uS
NOP ;15uS
NOP ;16uS
NOP ;17uS
NOP ;18uS
NOP ;19uS
NOP ;20uS
NOP ;21uS
NOP ;22uS
BTFSS _leftCount ;23,us <- this line causes a problem it seems too.
decfsz _dur, 1 ;24uS
goto cycleLeft ;26uS
endasm
ledSignal = ~GPIO.3
return
i am still struggling with what seems like eratic behavior with my PIC12F675.
I am trying to build an IR detection array thats smarter than a 555 timer or another hardwired 38500 oscillator and figured the small and tidy footprint of a 12F675 would be ideal.
right now, i am at the stage where i am trying to get IR LED to flash at 38500MHz for about 10ms. it seems to work fine, but when i add some "smarts" code, the whole thing stops working. here is the following code i am adding.
' ... Problem is between here
if (leftcount = duration) then
for i = 1 to 3
high ledsignal
pause 500
low ledsignal
pause 500
next i
low ledsignal
endif
' ... and here
to my mainline, the chip wont start.
the same happens if i add:
freqout gpio.3, 10, 38500
instead of the ASM delay block. I went down the ASM block path because it seems that freqout will not work with the 12F675 though i can't find that explicitly stated anywhere.
Bottom Line Issue:
~~~~~~~~~~~
It seems that when i add code that the chip does not like, it won't even start - the status LED blink i have at the top of my code won't even activate etc - nothing happens.
I am using a USB melabs programmer. i disconnect the USB from my computer between flashes to make sure i don't fry anything. i am using MicroCode studio 2.3.0.0 and PicBasic PRO compiler 2.46.
everyhing is soldered together to eliminate any potential of bad connections. i am using the following parts (http://www.hobbyengineering.com/H1765.html, http://www.hobbyengineering.com/H1992.html) without the 4Mhz resonator installed on the prototype board.
gpio.0 is a regular old red LED with a 220 ohm resistor on it.
gpio.3 is the detect from the IR Receiver (http://www.parallax.com/detail.asp?product_id=350-00014)
gpio.5 is the IR LED out with a 1K resistor (http://www.parallax.com/detail.asp?product_id=350-00017)
i have a .1uf bypass capacitor on the +5v and Ground leads of the detector
any thoughts or suggestions on what i am missing would be appreciated. probably something simple and silly.
it sure is frustrating. with that if block in there, the thing won't even start, i yank it out and it seems to work fine again.
is there a possibility that, since i am using the internal oscillator, i have overwritten some config (calibration) space or something that ensures the internal oscillator runs as it should? This question is nagging at me in the back of my mind.
here is the full code listing:
' Defines that set up the PIC
@ DEVICE pic12F675, INTRC_OSC_NOCLKOUT ' Internal Oscillator
@ DEVICE pic12F675, WDT_ON ' Watchdog Timer
@ DEVICE pic12F675, PWRT_ON ' Power-On Timer
@ DEVICE pic12F675, MCLR_OFF ' Master Clear Options set to Internal
@ DEVICE pic12F675, BOD_ON ' Brown-Out Detect
@ DEVICE pic12F675, PROTECT_OFF ' Code Protect off
@ DEVICE pic12F675, CPD_OFF ' Data EEPROM Protect off
'define xtal 4 ' don't think i need this - cant find it in the .inc
define OSC 4
' Initialise my Registers
TRISIO=%00001000 ' all output except gpio.3 is input
CMCON=%00000111 ' comparator module reg 6-1 page 35. Disable all
ANSEL=%00000000 ' A/D config reg 7-2. Set all pins to digital
'ADCON0=%00000000 ' reg 7-1 not required but shuts off A/D control
pause 1000
' Degine PINs
ledSignal var GPIO.0
leftIRLed var GPIO.5
irDetect var GPIO.3
' Constants
duration con 100
' Variables
i var word ' Genral purpose counter
dur var word
leftCount var word
' Code Mainline
' Blink the status led so we know we're ok.
high ledSignal
pause 2000
low ledSignal
pause 2000
'Mainline loop....
MainLoop:
' Check to see if we have activity on the left LED.
gosub LeftIR
' ... Problem is between here
if (leftcount = duration) then
for i = 1 to 3
high ledsignal
pause 500
low ledsignal
pause 500
next i
low ledsignal
endif
' ... and here
pause 20
Goto MainLoop
End
'******************************
'
' Subroutines ...
'
'******************************
'1/38500 = 0.000026
LeftIR:
leftCount = 0
dur = duration
asm
cycleLeft
BSF GPIO,5 ;1uS Begin HIGH duty cycle
NOP ;2uS each nop is 1uS long
NOP ;3uS
NOP ;4uS
NOP ;5uS
NOP ;6uS
NOP ;7uS
NOP ;8uS
NOP ;9uS
NOP ;10uS
NOP ;11uS
NOP ;12uS
NOP ;13uS
BCF GPIO,5 ;1uS Bigin Low
NOP ;14uS
NOP ;15uS
NOP ;16uS
NOP ;17uS
NOP ;18uS
NOP ;19uS
NOP ;20uS
NOP ;21uS
NOP ;22uS
BTFSS _leftCount ;23,us <- this line causes a problem it seems too.
decfsz _dur, 1 ;24uS
goto cycleLeft ;26uS
endasm
ledSignal = ~GPIO.3
return