I have just started to pre-program with the dsPIC33CK64MP102 and I want to turn on an LED that I have on the RA0 pin.

I have used mplabX's mmc to configure the pins and clock.

I have only activated the GPIO output of the RA0 and selected the Primary Oscillator at 8000KHz.

my code is the following:

#include "mcc_generated_files/system.h"
#include "mcc_generated_files/pin_manager.h"

int main(void)
  while (1)
return 1; 

From what I have seen in the pin_manager.h file with LED_Toggle (); I should be able to turn on the led.

In principle when I debug with the PICKIT3 I don't have any errors.

Do I need to call any other instruction to be able to turn on the LED?

The clock configuration is correct?

  • \$\begingroup\$ "In principle when I debug with the PICKIT3 I don't have any errors." - Have you actually tried it? If so, what happens? \$\endgroup\$ – Bruce Abbott Feb 11 at 23:11
  • 2
    \$\begingroup\$ 'Toggle' doesn't mean 'turn on', it means 'change to the opposite state' - so since you're toggling in a loop, your LED is going to turn on and off and on and off faster than you can see. \$\endgroup\$ – brhans Feb 12 at 4:55
  • \$\begingroup\$ The microchip Code configurator is named MCC. Why do you revert my edit? microchip.com/mplab/mplab-code-configurator \$\endgroup\$ – Mike Feb 15 at 7:37
  • \$\begingroup\$ @Mike Sorry, I have made a mistake \$\endgroup\$ – Geo Feb 15 at 14:18

Often, when you try to come to terms with a big and unfamiliar technological stack, you find yourself in this nothing works situation. There are so many things that could be wrong that you can't even formulate a precise question.

To find the solution you need to go step by step:

  • Is the problem on micro-controller side, or is the problem on LED side?
    • Detach LED circuitry from the PIC, so the PIC output pin is isolated from anything else.
    • Put a break-point on the LED_Toggle call.
    • Use a multi-meter to measure the voltage at the output pin.
    • It should alternate between 0V and 3.xV each time you pass over LED_Toggle.
    • If it does, then the problem is in the circuit side.
    • If it does not, then the problem is in Micro-controller side.

If problem is Micro-controller side:

  • Rewrite the program without MCC. MCC is great on certain cases, but it hides complexity. When nothing is working, then it is very difficult to find the issue.
  • In PIC world, to set an output pin to 1, you have to:
    • Set the corresponding ANSELx to 0, so the port is digital.
    • Set the corresponding TRISx to 0, so the port is output.
    • Set the corresponding ODCx to 0, so the port is not open drain.
    • Set the corresponding LATx to 1, so the port outputs a 1, which will translate into 3.xV (the exact value depends on the power source).
    • See more details in dsPIC33CK64MP105 family data sheet at page 108.
  • Work your way until you can see the multi-meter reacting to the code as you expect.

If problem is circuit side:

  • Are all power sources under control?
    • The dsPIC33CK64MP102 accepts 3.0V to 3.6V, and you can connect to it, so this at least seems to work.
    • What is the power source of the LED? Is it fed directly from the PIC output pin? Is it controlled via a transistor?
    • Have you checked that the series resistor is correctly sized? If undersized, then your LED may be burnt. If oversized, then your LED actually glows, but you don't notice it.
  • Does the LED light at all?
    • If not yet done, disconnect the led circuitry from the PIC pin
    • Connect the input of the LED circuitry directly to the power source.
  • Work your way until you can see the LED turning on with your own eyes.

At some point in this process you will either find the problem, or be able to formulate a specific question in SO.

If you don't have a multi-meter, then buy one. Can be cheap, but you need one. You can't go about without measuring resistors, contacts and voltage.

Best of luck!


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.