dsPIC33: Perplexing programming and debugging problem with PICKIT 3 - Page 1
Forum section: electronics / general

author: sp00kd
author_rank: Newbie
timestamp: May 26, 2023, 05:15:05 pm
content: I am new here, so apologies if anything I do is not exactly protocol.I have a problem with a dsPIC33EV256GM102 chip with MPLAB X 6.00:I run into the following error when programming/debugging: "Failed to program device"This problem usually is because of choosing the wrong programming pins or incorrect wiring, but here are all the things I've done to try solve the issue:I have checked the ICDS pin selection.I have checked and confirmed continuity from the PICKIT to the pins on the IC.I have tried both powering the device with the PICKIT and externally.I have tried other versions of MPLAB X (5.4 and 6.1)I have tried a different PC.I have tried a different PICKIT (also 3)I have another almost identical PCB that works fine.Here's where things get weird:I have unsoldered the chip and replaced it with another PIC and have the same problem.The problem momentarily went away for a while with no physical changes.Attempting the debug (as opposed to programming) made the problem come back.Here are my config stuff (Programmer is connected to pins 1, 14 and 15):// FSEC#pragma config BWRP = OFF // Boot Segment Write-Protect Bit (Boot Segment may be written)#pragma config BSS = DISABLED // Boot Segment Code-Protect Level bits (No Protection (other than BWRP))#pragma config BSS2 = OFF // Boot Segment Control Bit (No Boot Segment)#pragma config GWRP = OFF // General Segment Write-Protect Bit (General Segment may be written)#pragma config GSS = DISABLED // General Segment Code-Protect Level bits (No Protection (other than GWRP))#pragma config CWRP = OFF // Configuration Segment Write-Protect Bit (Configuration Segment may be written)#pragma config CSS = DISABLED // Configuration Segment Code-Protect Level bits (No Protection (other than CWRP))#pragma config AIVTDIS = DISABLE // Alternate Interrupt Vector Table Disable Bit (Disable Alternate Vector Table)// FBSLIM#pragma config BSLIM = 8191 // Boot Segment Code Flash Page Address Limit Bits (Enter Hexadecimal value)// FOSCSEL#pragma config FNOSC = FRC // Initial oscillator Source Selection Bits (Internal Fast RC (FRC))#pragma config IESO = ON // Two Speed Oscillator Start-Up Bit (Start up device with FRC,then automatically switch to user selected oscillator source)// FOSC#pragma config POSCMD = NONE // Primary Oscillator Mode Select Bits (Primary Oscillator disabled)#pragma config OSCIOFNC = ON // OSC2 Pin I/O Function Enable Bit (OSC2 is general purpose digital I/O pin)#pragma config IOL1WAY = OFF // Peripheral Pin Select Configuration Bit (Allow Multiple reconfigurations)#pragma config FCKSM = CSDCMD // Clock Switching Mode Bits (Both Clock Switching and Fail-safe Clock Monitor are disabled)#pragma config PLLKEN = ON // PLL Lock Enable Bit (Clock switch to PLL source will wait until the PLL lock signal is valid)// FWDT#pragma config WDTPOST = PS32768 // Watchdog Timer Postscaler Bits (1:32,768)#pragma config WDTPRE = PR128 // Watchdog Timer Prescaler Bit (1:128)#pragma config FWDTEN = OFF // Watchdog Timer Enable Bits (WDT and SWDTEN Disabled)#pragma config WINDIS = OFF // Watchdog Timer Window Enable Bit (Watchdog timer in Non-Window Mode)#pragma config WDTWIN = WIN25 // Watchdog Window Select Bits (WDT Window is 25% of WDT period)// FPOR#pragma config BOREN0 = OFF // Brown Out Reset Detection Bit (BOR is Disabled)// FICD#pragma config ICS = PGD2 // ICD Communication Channel Select Bits (Communicate on PGEC2 and PGED2)// FDMTINTVL#pragma config DMTIVTL = 0x0 // Lower 16 Bits of 32 Bit DMT Window Interval (Enter Hexadecimal value)// FDMTINTVH#pragma config DMTIVTH = 0x0 // Upper 16 Bits of 32 Bit DMT Window Interval (Enter Hexadecimal value)// FDMTCNTL#pragma config DMTCNTL = 0x0 // Lower 16 Bits of 32 Bit DMT Instruction Count Time-Out Value (Enter Hexadecimal value)// FDMTCNTH#pragma config DMTCNTH = 0x0 // Upper 16 Bits of 32 Bit DMT Instruction Count Time-Out Value (Enter Hexadecimal value)// FDMT#pragma config DMTEN = DISABLE // Dead Man Timer Enable Bit (Dead Man Timer is Disabled and can be enabled by software)// FDEVOPT#pragma config PWMLOCK = ON // PWM Lock Enable Bit (Certain PWM registers may only be written after key sequence)#pragma config ALTI2C1 = OFF // Alternate I2C1 Pins Selection Bit (I2C1 mapped to SDA1/SCL1 pins)// FALTREG#pragma config CTXT1 = NONE // Interrupt Priority Level (IPL) Selection Bits For Alternate Working Register Set 1 (Not Assigned)#pragma config CTXT2 = NONE // Interrupt Priority Level (IPL) Selection Bits For Alternate Working Register Set 2 (Not Assigned)

author: JoeyG
author_rank: Regular Contributor
timestamp: May 26, 2023, 05:51:15 pm
content: while it may take some time to respond. Try a support ticket atwww.microchip.com/support.Have you validated the PICKit3 works with other mcus on other target boards.Is the PICkit Support tool plug-in updated in MPLAB X6.00Have you validated your target hardware by testing the PICKit3 and MPLAB X tool chain on other known validated hardwareeghttps://www.microchip.com/en-us/development-tool/dm330018

author: sp00kd
author_rank: Newbie
timestamp: May 26, 2023, 06:05:00 pm
content: As I said in the post: I can program another chip on a different board with the same project and settings. Its the one specific board that has this issue despite changing out the MCU.

author: hans
author_rank: Super Contributor
timestamp: May 26, 2023, 06:06:09 pm
content: If the problem seems intermittent yet remains when PIC has changed, then that kind of rules out incorrect schematic.Although assumptions is mother of all f****ups, so I will know certainly without a schematic. Could still have faulty connections.I would validate all supply rails voltages.Also check Vcap pin voltage when powered on (typ 1.8V), and if possible, measure if right capacitance is installed (4.7uF min, 10uF recommended, low ESR).Check MCLR voltage and pull-up resistance.If using external oscillator, perhaps check if it's running with scope. Although I don't think a PIC needs it to be programmed.

author: sp00kd
author_rank: Newbie
timestamp: May 26, 2023, 06:16:13 pm
content: I immediately went and checked the VCAP and found that there is a loose solder connection there! This problem was driving me insane and I wouldn't be surprised if you just solved it, will let you know if it works once I resolder the connection.

author: sp00kd
author_rank: Newbie
timestamp: May 26, 2023, 07:39:45 pm
content: Thanks Hans. Resoldering Vcap fixed the issue. I did not realize that a loose Vcap would lead to such strange behaviour where the MCU mostly works but programming is broken. Really appreciate pointing out the potential problem.

author: SiliconWizard
author_rank: Super Contributor
timestamp: May 26, 2023, 07:52:45 pm
content: Vcap is the output capacitor for the internal voltage regulator. Without it, the internal regulator (which provides the supply for the internal logic) is going to oscillate/go bonkers, so it's basically as though your powered a logic chip with a very nasty supply. It won't work properly.

author: JoeyG
author_rank: Regular Contributor
timestamp: May 30, 2023, 03:34:55 am
content: For FUTURE reference - Here is the dsPIC programming specifications.Its shows connections on page 2 figure 2.2And electrical requirements on page 64 , 65 showing the rise and fall time requirements of the programming signals.https://ww1.microchip.com/downloads/en/DeviceDoc/dsPIC33EVXXXGM00X-10X-Families-Flash-Programming-Specification-DS70005137H.pdfThe challenge is to have Vdd and Vcap properly power cycled down to Vss for the next programming grab of the pins.