hey renguo,
First of all, check the demo code included in application note to see which peripherals that this application is utilizing with. Normally those two PICs share the same cpu architecture and type of peripherals, the only difference is the amount of peripherals (timmers) and the size of flash memory and number of avaliable I/Os.
Secondly, does dspic33fj16gs502 has enough necessary peripherals (I/Os,timers, ADC, PWM..etc that you need in your application) as dspic33fj16gs504? if yes, the answer is yes.
finally, which hardware platform are you debugging with, did you create your own PCB or you are using a PIM model with microchip's development board? check the schematic very carefully to see if you miss something. I suggested that you start with the official development board, and design your own PIM which costs less.
I hope those helps.
Mr.Ye