Jump to content
Sign in to follow this  
iano

oscillating outputs

Recommended Posts

I'm a new user of C2C but I have used PIC assembler a lot. When I write a simple program in C2C which only includes the

system include, sets the clock speed to 4mhz via a pragma and then sets portc to 0xaa, my logic probe shows that the

output values are correct - however the probe shows them

oscillating. The same code in assembler works without oscillation. I'm guessing that I have stuffed up somewhere ? Help ! Thanks, Ian

 

Thanks moyoyoyo for you help. I tried some more code without any success - I'm sorry I should have included code the first time round. I realise that I am using some obselete functions (but believe they are still supported). I am using the PIC 16f877 and the same hard ware as reported before works when I write an assembler program with another program ! The target is correctly set in the project.

 

 

#include

#pragma CLOCK_FREQ 4000000

 

main()

{

set_tris_b(0x00);

output_port_b(0xaa);

set_tris_a(0x00);

output_port_a(0xaa);

while(1);

}

 

This code is so simple I can't believe that it doesn't work !

 

Help !

Share this post


Link to post
Share on other sites

Could you include the code? it is poible that you have a loop somewhere or you have an error somewhere that makes the code behave as a loop. An example would be when a counter counts past its limit. I think a counters limit is 256. I had a similar problem with an LCD. I used a string to store my mesages. I forgot to add the terminator part. That is, my code kept printing the next character but because it didn't know when to stop it reach a limit and it looped back to another section of my code.

 

May I suggest adding a LED and a 3 second delay. You need visual aids to help trouble shoot things.

 

or try a simple code like

pragma#   4000000

set_status(rpx,x1);

TRISC 0xXX

set_status(rp0,x2);

void main (void)

{

 output_high_port_x1( x2 );  /* sets a pin high */

 while (1);    /* code will lop here forever. the pin set

                    above will stay set forever */

}

the while(1); makes the compiler loop on the while comand for infinity. Without it, it is possible that the code will repeat and you will see the on/off problem.

 

you can also use portc=0xaa to set the whole port.

The Xs on the code above means you must fill in the blanck with the proper value, depending on the device you are using.

 

One last thing, depending on the device you might have to set some register a certain way. An example are devices that have analog capabilities. On a pic of this nature you must make sure to tell the compiler to set those pins to digital mode, other wise the pic will think that that pin is used for an analog signal.

 

as a disclaimer might code might have some errors in it. I don't have my reference in fromt of me for the proper syntax, but the idea is there.

Share this post


Link to post
Share on other sites

oops I've been away for so long, I bet by now you must have found a solution to your problem. I'm taking a while guess here but did you make sure that the watch dog timer is off.

 

   Are you using the same programer to burn your program and the same software? I don't have my c2c software set up properly. so, what  do is convert from C to assembler in c2c. Then I open mplab and convert the assembler into hex. Then I open my programer program and burn the PIC from there. In my programer theres an option to turn off the watchdog timer. I use the EPIC Plus PICmicro Programmer and I had to set 3 different options to disable the watch dog timer. diferent programers have diferent settings and options. I think you can also disable the watchdog timer through software (c2c).

 

Do you have an oscilloscope? this is the most valuable tool you can have. check the frequency of the oscilation then compare thatnumber to the number given in the specs for the watchdog timer. remember to compesate for the clock frequency.

 

If you have mplab which is a free software or picant you can simulate your code. make sure that when you compile the code in C2C it doesn't add something that makes it loop.

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...