Menu

PIC loads down line

Help
Chris S
2020-06-10
2020-06-11
  • Chris S

    Chris S - 2020-06-10

    So I have a rather interesting problem that I can seem to locate the cause of. I am building a PID controller that will control a heater and to do this, I need to sense the AC line. The way I did this is to use a transformer with a bridge rectifer and then scale it down using a voltage divider to make sure the peak voltage is no more than 5V (which is my IC power). In code, I basically sense when this input hits 0.

    The first IC I tried, which is a 18F25K20 works perfectly. The "sense" input is as it should. I see a nice 120Hz wave on the input and it doesnt change. My example code I came up with works. It senses when the input is 0 and changes the output (It actually serves to trigger Timer 2 which sets a port on and off)

    The problem comes in when I use the actual chip thats going in its intended application; a PIC18F26Q10. The only major difference between the two is the PPS. What happens is this: When the chip is erased and blank, I see the correct wave form, which is a 120Hz rectified wave thats 5V peak. When the chip is programmed the line gets dragged down somehow and becomes roughly a 1V DC line. There is a small square wave ontop of this line, but it has a DC offset to it. Its nothing major that can be sensed with a PIC though.

    So I thought that maybe there's an error to my board, so I eliminated that out by using a the DIP version of the 26Q10, and connected up a rectified AC line thats 5Vpk. Same issue. The waveform is perfect up until I connect it to the PIC and program the PIC.

    So to make matters more interesting, I also desoldered the IC on the board I was working on to make sure nothing else was messing it up. I get the correct waveform without the PIC in circuit.

    My thinking was maybe the pin is trying to output when I need it as an input, so i added in a bit of code to make sure its forced. I am using input RB0 and really cant change it because the board is made already. I also chose RB0 because I want to use INT0.

    DIR PORTB.0 IN 'INT0 or ZCD
    Dim ZCD as Bit
    ANSELB0=0
    TRISB0=1
    ODCONB=0
    SLRCONB=1
    INLVLB=1
    PORTB.0=ZCD
    ZCDMD=1
    CMP1MD=1
    CWG1MD=1
    

    Still does the same thing. So Im kind of lost here. It bothers me how it works perfectly fine on a 25K20 and not the 26Q10. I figure I would ask here in case its a complier issue and not a hardware (aka Microchip) issue.

     
  • Anobium

    Anobium - 2020-06-10

    What version of Great Cow BASIC? We should start with that question. Look at the first line of the ASM file.

     
  • Anobium

    Anobium - 2020-06-10

    The Q10 is a very different chip. I would recommend recreating PPS using PPSTool to ensure you have all the registers correct.

    Lets start with the version of Great Cow BASIC first.

     
    • Chris S

      Chris S - 2020-06-10

      Anobium, GCB v0.98.06.

       
    • Chris S

      Chris S - 2020-06-10

      Anobium

      Just want to give an update. I think Ive narrowed it down to something in GCB. I got some code running on MPLABX XC8 that just switches an output on and off based on that Input Pin. Im going to see what settings the PPS gives on XC8 and compare it with GCB, but with XC8 the circuit functions as normal.

      Ive included my XC8 zip file.

       
      • Anobium

        Anobium - 2020-06-10

        My guess is PPS.

        Did you use the PPSTool within your Great Cow BASIC installation?

         
        • Chris S

          Chris S - 2020-06-10

          No, but I did use it to compare the results I came up with from the datasheet. I wanted to try and do it on my own so I understand how PPS works. I'll try the PPS tool and report back.

           
          • Chris S

            Chris S - 2020-06-10

            Figured it out after playing around in XC8 a bit. The magic didnt happen until I looked at the config files XC8 gave. One option in particular popped out at me: ZCD On/Off. By default its on in the GCB datafiles, so turning it off was what made it work.

            I confirmed later on after it was working that the datasheet gave this tid bit on page 385:

            ZCD Config fuse = 1 Zero-cross detect is disabled. ZCD pin operates according to PPS and TRIS controls.<

            To avoid confusion, the bit in inverted.So for anyone coming across this and who has the same issue set the bit like this:

            #config ZCD=OFF
            

            The pin works as intended.

             

            Last edit: Chris S 2020-06-10
            • Anobium

              Anobium - 2020-06-11

              Excellent work. Cheers.

               

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.