View previous topic :: View next topic |
Author |
Message |
alan
Joined: 12 Nov 2012 Posts: 357 Location: South Africa
|
[SOLVED] dsPIC33EP64GP506 |
Posted: Mon Oct 07, 2013 5:28 am |
|
|
Hi All
Battling to get the PIC to work. Seems to start and then fall over. Code use to test below.
Code: | #include <33EP64GP506.h>
#FUSES NOWDT //No Watch Dog Timer
#FUSES NOJTAG //JTAG disabled
#FUSES OSCIO //OSC2 is general purpose output
#FUSES NOCKSNOFSM //Clock Switching is disabled, fail Safe clock monitor is disabled
#FUSES NOIESO //Internal External Switch Over mode disabled
//#FUSES FRC
#device ICSP=1
#use delay(clock=7.37Mhz)
void main()
{
while(TRUE) {
output_a(0xffff);
output_d(0xffff);
output_a(0x00);
output_d(0x00);
}
} |
Above code output a high on the pins.
If I change to
Code: | output_a(0x0000);
output_d(0x0000);
output_a(0xffff);
output_d(0xffff);
|
still a high on the pins.
If I only use
Code: | output_a(0x00);
output_d(0x00);
|
a low on pins.
Pulling my hair out on this one, probably something stupid. Any help will be appreciated.
CCS 5.012
Regards
Last edited by alan on Mon Oct 07, 2013 6:46 am; edited 1 time in total |
|
|
alan
Joined: 12 Nov 2012 Posts: 357 Location: South Africa
|
|
Posted: Mon Oct 07, 2013 6:13 am |
|
|
Loaded the project in MPLABX and run the debugger.
If I stop the debugger, the PC will stop on one of the output_x Lines, which I assume then that the program are running. If I single step then output toggles correctly. If I then select run, no toggling, but when single stepping again it works. |
|
|
jeremiah
Joined: 20 Jul 2010 Posts: 1349
|
|
Posted: Mon Oct 07, 2013 6:16 am |
|
|
I would imagine measurement error in this case. You are switching super fast. Try putting a delay_ms(500) in between the highs and lows.
Code: |
delay_ms(500);
output_a(0xffff);
output_d(0xffff);
delay_ms(500);
output_a(0x00);
output_d(0x00);
|
|
|
|
alan
Joined: 12 Nov 2012 Posts: 357 Location: South Africa
|
|
Posted: Mon Oct 07, 2013 6:29 am |
|
|
Hi jeremiah
Just did that, and seems to work now. I just did that as I tried at 1st with an int that didn't work, so was worried that my clock not working. Can't believe the processor is so fast on 7.37MHz that it can't drive the output.
Thanks for your time.
Regards |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19513
|
|
Posted: Mon Oct 07, 2013 7:44 am |
|
|
Is the pulse the length you expect?.
The chip may actually be running much faster than you think.
You need to use:
Code: |
#FUSES NOWDT //No Watch Dog Timer
#FUSES NOJTAG //JTAG disabled
#FUSES OSCIO //OSC2 is general purpose output
#FUSES NOCKSNOFSM //Clock Switching is disabled, fail Safe clock monitor is disabled
#FUSES NOIESO //Internal External Switch Over mode disabled
#device ICSP=1
#use delay(internal=7.37Mhz)
|
clock=7.37MHz, means 'I am giving you a 7.37MHz clock'
internal=7.37MHz, tells the compiler to _use_ the internal 7.37MHz clock.
By default, the PLL will be enabled, and I'm not sure what divider rate will be selected, so your chip may well have been running at something like 60Mhz....
Best Wishes |
|
|
alan
Joined: 12 Nov 2012 Posts: 357 Location: South Africa
|
|
Posted: Mon Oct 07, 2013 8:06 am |
|
|
Funny thing is internal or clock gives the same result. I added a delay_ms(50) between the statements and measured 50ms.
Regards |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19513
|
|
Posted: Mon Oct 07, 2013 8:36 am |
|
|
Not 'funny', just luck. It depends what the default settings are, which changes with compiler version, and chips. With 'internal' specified, the compiler is meant (...), to calculate things for you. With 'clock' you are dependant on what the defaults happen to be. Several fuses recently changed meanings between CCS versions in some other areas, hence worth not pushing things. I wondered if the original code might have been producing a much higher frequency pulse than you expected, which suggested the 'possibility' that the CPU clock might be higher than expected....
Best Wishes |
|
|
|