PIC12F675 trouble


Closed Thread
Results 1 to 6 of 6
  1. #1
    russman613's Avatar
    russman613 Guest

    Default PIC12F675 trouble

    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
    Attached Files Attached Files
    Last edited by russman613; - 27th February 2006 at 15:32. Reason: tryint to add an attachment

  2. #2
    Join Date
    May 2004
    Location
    New England
    Posts
    164


    Did you find this post helpful? Yes | No

    Default

    Hi Russ,

    EDIT - on this line of code...
    BTFSS _leftCount ;23,us <- this line causes a problem it seems too.

    You did not specify which BIT to test - it's also a WORD variable - maybe someone here can answer if BTFSS will work on a WORD??

    OOpps - I thought the 12F's WERE 12-bit core - sorry!
    EndEDIT

    ====

    I have not looked over the rest - but here's a list of unsupported commands fort the 12bit cores:
    from PBP 2.44 'new.txt' file

    Commands that are not supported for the 12-bit core PICmicro MCUs:

    Command Reason
    Adcin No internal ADCs
    Data No on-chip EEPROM
    Dtmfout Not enough RAM or stack
    Eeprom No on-chip EEPROM
    Erasecode No flash devices
    Freqout Not enough RAM or stack
    Hpwm No hardware PWM
    Hserin No hardware serial port
    Hserin2 No hardware serial port
    Hserout No hardware serial port
    Hserout2 No hardware serial port
    On Interrupt No Interrupts
    Read No on-chip EEPROM
    Readcode No flash devices
    Resume No Interrupts
    Serin2 Not enough RAM or stack
    Serout2 Not enough RAM or stack
    USBIn No USB devices
    USBInit No USB devices
    USBOut No USB devices
    Write No on-chip EEPROM
    Writecode No flash devices
    Xin Not enough RAM or stack
    Xout Not enough RAM or stack
    Last edited by Archilochus; - 27th February 2006 at 17:09.

  3. #3
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Hi Russ,

    In the MainLoop, the IF (leftcount = duration) will never evaluate true.

    duration is a constant(100), and leftcount never gets assigned anything but 0. Maybe you were thinking that BTFSS would do something, but that means "Bit Test File Skip if Set, so it's looking for a bit number that wasn't specified. Are you trying to test leftcount for a specific value, or trying to set the value?

    Archilochus,

    The 12F675's are actually 14-bit core's. I have no idea why they called them 12's. 12C508's are 12-bit, and the 12F508's are 12-bit, so you would think 12F629/675/683's are too. but, Not!
    <br>
    DT

  4. #4
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    btfss is for testing individual "bits" in a file register.

    You would use btfss _leftCount,1 to test bit position 1 in leftCount. This
    seems like an unnecessary test at any rate since you're clearing leftCount
    at the entry point to your asm routine, and leftCount will always be zero.

    Also be aware that you're only accessing the low bytes in your leftCount
    and dur word variables the way you're when doing it.

    To access the high byte in dur you would use decfsz _dur+1,f. Dur is a pointer
    to the low byte. Adding _dur+1 moves the pointer to the next byte location
    in ram.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  5. #5
    russman613's Avatar
    russman613 Guest


    Did you find this post helpful? Yes | No

    Default

    awesome information - i love it when there is a simple answer.

    thx for the tips and for pointing out my issue. i will try to fix up what you guys have pointed out this evening and retry. also looks like new.txt is worth a closer look.

    any idea why the PIC seems to just hang? I would expect that it would at least toggle the statusLED for me that i've set up before it gets to a piece of bad code. or, am i to expect "unexpected" behavior anytime i muck up the logic anywhere in the program?

    russ

  6. #6
    russman613's Avatar
    russman613 Guest


    Did you find this post helpful? Yes | No

    Default

    awesome information - i love it when there is a simple answer. i had actually meant that line to read:

    btfss gpio, 3;
    incfsz _leftCount, 1 ;23,us - this line causes a problem it seems too.


    thx for the tips and for pointing out my issue. i will try to fix up what you guys have pointed out this evening and retry. also looks like new.txt is worth a closer look.

    any idea why the PIC seems to just hang? I would expect that it would at least toggle the statusLED for me that i've set up before it gets to a piece of bad code. or, am i to expect "unexpected" behavior anytime i muck up the logic anywhere in the program?

    russ
    Last edited by russman613; - 27th February 2006 at 18:49.

Similar Threads

  1. Pic12F675 serial voltmeter
    By GioppY in forum Code Examples
    Replies: 22
    Last Post: - 20th November 2010, 13:20
  2. PIC12F675 problem with port 5
    By NL2TTL in forum mel PIC BASIC
    Replies: 2
    Last Post: - 5th June 2009, 01:23
  3. MCLR causing trouble . .
    By shahidali55 in forum General
    Replies: 10
    Last Post: - 21st December 2007, 12:20
  4. SERIN with a PIC12F675
    By ewandeur in forum Serial
    Replies: 4
    Last Post: - 30th July 2007, 15:04
  5. Erratic PIC12F675 behavior
    By russman613 in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 27th February 2006, 14:46

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts