• AVR Freaks

Helpful ReplyNo output on GPIO pins on PIC12F675

Author
tangent
New Member
  • Total Posts : 3
  • Reward points : 0
  • Joined: 2013/12/15 06:08:05
  • Location: 0
  • Status: offline
2013/12/15 06:55:32 (permalink)
0

No output on GPIO pins on PIC12F675

I am trying to flash an LED using a PIC12F675, but I'm not seeing the expected output on the GPIO pins. I had this working on a PIC16F690, and have made all the changes I can think of for the PIC12F675 but can't get it working. Using the scope, I can see a clock signal on GPIO4 at 1MHz (I was expecting 4MHz). GPIO3 is high and the remaining GPIO pins are floating.
 #include <htc.h> 

__CONFIG(FOSC_INTRCCLK & WDTE_OFF & PWRTE_OFF & MCLRE_OFF & CP_OFF & CPD_OFF & BOREN_OFF);

//oscillator selection: internal, clock out on 4, I/O on 5
//watchdog off
//power up timer disabled
//Master clear reset line pin Function off (i.e. no reset switch)
//code protection off
//data code protection off
//brownout reset off

unsigned int uintDelayCount = 0;

void main(void)
{
    //digital IO
     ANSEL = 0x00;

    //no A/D
    ADCON0 = 0x00;

    //no comparator
    CMCON = 0x07;

    //no voltage reference
    VRCON = 0x00;

    //switch timer 1 to not use GP5 as an external clock
    T1CONbits.TMR1CS = 0x0;

    //Use TRISIO to set GPIO to all outputs except gp3 because it's input only
    TRISIO = 0x08;

    //Loop forever
    while ( 1 )
    {
        uintDelayCount = 0;
        while ( uintDelayCount < 500 )
        {
            uintDelayCount++;
        }

        GPIO = 0x27;
       
        uintDelayCount = 0;
        while ( uintDelayCount < 500 )
        {
            uintDelayCount++;
        }

        GPIO = 0x00;
    }
}

 
Hardware: programming with a PICkit2 with the PIC12F675 in a low pin count demo board, with an LED and resistor between GPIO5 and GND.
Software: compiling with
picc --chip=12F675 --outdir=obj -P blink.c
and programming with
pk2cmd -PPIC12F675 -E -M -F obj/blink.hex -Y -T -R -GI -GC

Can anyone see what I missed?
Thanks for your time.
#1
DavidBLit
Super Member
  • Total Posts : 1579
  • Reward points : 0
  • Joined: 2012/02/18 13:08:48
  • Location: The Land of Confusion
  • Status: offline
Re:No output on GPIO pins on PIC12F675 2013/12/15 08:59:48 (permalink)
+2 (1)
Confirm that your LED's GPIO isn't connected to the ICSP connector's pin 6.
#2
tangent
New Member
  • Total Posts : 3
  • Reward points : 0
  • Joined: 2013/12/15 06:08:05
  • Location: 0
  • Status: offline
Re:No output on GPIO pins on PIC12F675 2013/12/15 10:34:34 (permalink)
0
GPIO5 isn't connected to any of the ICSP pins (but ICSP pin 6 is connected to GPIO4). I tried removing the PICKit2 and running the PIC from a separate power supply, and got the same results, so I don't think the PICKit is interfering.
 
I also noticed that I've lost the OSSCAL value, but it's not clear to me whether that would prevent the PIC running at all, or just affect its clock speed. I experimentally set OSCCAL to 0x80 (read somewhere that that was a reasonable default) but that didn't make any difference that I could detect.
 
#3
Ian.M
Super Member
  • Total Posts : 13267
  • Reward points : 0
  • Joined: 2009/07/23 07:02:40
  • Location: UK
  • Status: offline
Re:No output on GPIO pins on PIC12F675 2013/12/15 10:58:52 (permalink) ☄ Helpful
+4 (2)
Fosc/4 output for your chip *IS* 1MHz. It only has a 4MHz internal oscillator.
 
Disabling /MCLR, and selecting an internal oscillator in the CONFIG and also configuring the ICSP pins as outputs within 500ms of powerup is problematic on PIC12F629, PIC12F675, PIC16F630 and PIC16F676 because they keep their OSCCAL (oscillator calibration value) as a RETLW at the top of the program memory.   The problem is the OSCCAL RETLW is not erase protected so the programmer must read the memory before erasing the chip and write back the last location after the erase completes.  However that CONFIG and I/O usage prevents reliable entry into programming mode (unless the programmer is using Vpp first mode - PK2CMD -X option) and the OSCCAL RETLW gets silently corrupted.   As the C startup code calls it, if the RETLW opcode is missing, execution wraps back around to the RESET address and the PIC is then stuck in an endless loop.

Did you reprogram the complete OSCCAL RETLW (0x34nn) or just the data byte or did you try to override it?

The Windows PICkit 2 standalone GUI application reports if the OSCCAL RETLW  is bad when you read the chip and also has a command to calculate and reprogram the correct value.   I presume you are using the command line tools because you are a Linux user, so if you insist on wearing a hair shirt, here's how to build and use a jig for recalibration. mr green
 
As a quick test, try rebuilding with  PICC, adding the --RUNTIME:oscval:80 option (user manual section 2.7.50) to override OSCCAL and reprogramming your PIC adding the PK2CMD -X option for Vpp first mode.
post edited by Ian.M - 2013/12/15 11:15:16
#4
tangent
New Member
  • Total Posts : 3
  • Reward points : 0
  • Joined: 2013/12/15 06:08:05
  • Location: 0
  • Status: offline
Re:No output on GPIO pins on PIC12F675 2013/12/15 19:36:59 (permalink)
+2 (1)
Ah, thanks, it was an OSCCAL RETLW problem. I'd set and checked the calibration value using
pk2cmd -PPIC12F675 -MC -MP -F obj/blink.hex -YP -E -T -R -GP3FF-3FF -U80
which gave the value at location 3FF as 000080 - i.e. the calibration value was set but the RETLW instruction was missing. Solution:
pk2cmd -PPIC12F675 -MC -MP -F obj/blink.hex -YP -E -T -R -GP3FF-3FF -U3480
to write both the value and instruction - and lo, the scope shows that my LED is happily blinking grin
 
I still have the same code, CONFIG, and VDD-first settings, so I will watch out for silent corruption of that data, but a few reprogrammings without the -U option have not clobbered it yet.
 
Out of interest, I had a play with the extremes of the calibration value, and found that the speed ranged from 5.3MHz at FF, to 3.3MHz at 00.
 
Many thanks for your help.
 
post edited by tangent - 2013/12/15 19:44:26
#5
Jump to:
© 2019 APG vNext Commercial Version 4.5