CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

pic10f206 and delay_ms delay issue...

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
KamPutty
Guest







pic10f206 and delay_ms delay issue...
PostPosted: Fri Feb 17, 2006 5:19 pm     Reply with quote

Hi all,

I'm starting a project using pic10f206's and I was getting everything setup. I got the ICD2 all connected to the pic10f206, and I can program it just fine using CCS and MPLab.

Now.....

One of my "are you working" tests is just to strobe a LED as a visual "I am working".

Now, I can turn on the LED, OFF etc. just fine.
When I use a "delay_ms" command, all hell breaks loose! In my case, it locks up (or goes to sleep/delay for a verrrrry long time!).

Here is my code:


Code:

#include <10F206.h>

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES NOMCLR                     //Master Clear pin: disable
#FUSES NOPROTECT                  //Code protected from reads
#use delay(clock=4000000)

#define LED PIN_B2

main()
{
    int32   timer;

    setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
    setup_comparator(NC_NC);

    output_low(PIN_B0);
    output_low(PIN_B1);
    output_low(PIN_B2);
    output_low(PIN_B3);

//    delay_ms(500);    // <--- uncomment this and we will *never* get below this code

    while(true)
    {
        output_high(LED);   // LED DOES turn on
        delay_ms(500);      // locked up?
        output_low(LED);    // never makes it here...
        delay_ms(500);
    }
}



I've moved the "output_high's" all over the place, and I can turn on the LED, or off. I've narrowed it down to the delay_ms funtion.

I removed the #delay pragma, and the compiler complained about the delay_ms's then...

My compiler versions are: 3.234 for all 3 types.

Any thoughts???

~Kam (^8*
KamPutty
Guest







PostPosted: Fri Feb 17, 2006 5:32 pm     Reply with quote

Also, if I do not call the setup_timer_0 method, it also does not work!

Code:

#include <10F206.h>

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES NOMCLR                     //Master Clear pin: disable
#FUSES NOPROTECT                  //Code protected from reads
#use delay(clock=4000000)

#define LED PIN_B2

main()
{
    setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);    // <-- if this is commented, the program does not run/sleeps/halts etc

    output_low(PIN_B0);
    output_low(PIN_B1);
    output_low(PIN_B2);
    output_low(PIN_B3);

//    delay_ms(500);    // <--- uncomment this and we will *never* get below this code

    while(true)
    {
        output_high(LED);   // LED DOES turn on
        delay_ms(500);      // locked up?
        output_low(LED);    // never makes it here...
        delay_ms(500);
    }
}



Confused

~Kam (^8*
Ttelmah
Guest







PostPosted: Sat Feb 18, 2006 4:58 am     Reply with quote

First minor comment you cannot have 'output_low(PIN_B3)'. This pin is input only.
I seem to remember there was a fault on the early 10F compiler versions, that led to the configuration fuses not being set correctly. Load the file into your programmer, and check what the fuse settings are. The code is OK, _but_ I suspect you are actually getting a watchdog timeout, and hence it'll die in the first long delay.
If I remember correctly, the compiler inserts the configuration at 0x1FF, which is correct for the 10F204, but not fo the 10F206 (which requires it at 0x3FF). If you have PCW, device editor,will allow you to check/change this.
The code as posted compiles/runs OK for me on 3.234, but I may well have already changed that location.

Best Wishes
KamPutty
Guest







PostPosted: Sat Feb 18, 2006 10:58 am     Reply with quote

Thanks for the info.

but when I looked at the pic10f206 in the Device Editor, the memory config location was set to 03ff already. (BUMMER!)

Could it be something electric? Could I have wired it wrong? The only external part I am using is a 0.1uf cap from +5 and ground. Okay, I do have a res and a LED to show power, and also the res and LED that I am strobing.
But as for the pic, there is nothing other then the pic! Also, I have the ICSP connector wired (no parts other then wire!) and that is connected to the ICD2, and that all seems to work...

~Kam (^8*
Ttelmah
Guest







PostPosted: Sat Feb 18, 2006 3:37 pm     Reply with quote

Yes, it could very easily be a hardware issue. How much current does the LED draw?. How is the supply generated?. What is connected to the other pins?. You imply nothing. If so, put a resistor to 5v, on GP3. This pin though selected to not be 'MCLR', is still different from any other PIC pin, in having no diode protection (this is because it is aso the 'Vpp' pin, and hence has to be drivable to a higher voltage). Since it is 'input only', it is not being driven, and if it floats outside the supply rail range, it will cause the reset to operate (there is an internal diode structure here, which causes this).

Best Wishes
KamPutty
Guest







PostPosted: Sat Feb 18, 2006 6:20 pm     Reply with quote

Ttelmah wrote:
it will cause the reset to operate (there is an internal diode structure here, which causes this).

Best Wishes


I think your summary about the reset is correct. I've been playing with it, and if I run the following program

Code:

#include <10F206.h>

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES NOMCLR                     //Master Clear pin: disable
#FUSES NOPROTECT                  //Code protected from reads
#use delay(clock=4000000)
                   
#define LED PIN_B2

main()
{
    setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);

    output_low(LED);
    delay_ms(16);      // <--- change this
    output_high(LED);
    sleep();

//    while(true)
//    {
//        output_high(LED);   // LED DOES turn on
//        delay_ms(500);      // locked up?
//        output_low(LED);    // never makes it here...
//        delay_ms(500);
//    }
}



If the delay < 17, then LED lights.
If the delay>17, then the uP resets.

I can see the reset because at delay_ms(16), I see the LED turn OFF and then ON. The fact that I see a flicker means to me that the uP is resetting and rerunning. off/on, off/on etc.

Also, as you recommended, I did put a 10k res from gp3 to +5v., same.
The LED's I'm using are my "standard" leds, where I use a 270 ohm res with them. If memory serves right, they're drawing about 20u amps(?) each.

The power supply is my same power supply I use with everything. I think it os okay. It's a DC Regulated. 0~30V/3A.

I just did another test with this code:

Code:

#include <10F206.h>

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES NOMCLR                     //Master Clear pin: disable
#FUSES NOPROTECT                  //Code protected from reads
#use delay(clock=4000000)
                   
main()
{
    setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);

    output_high(PIN_B2);    // turn on LED
    delay_ms(10);           // lets delay.
                            // If commented, LED stays OFF
                            // if uncommented (used), LED stays ON. (Flicker)
    output_low(PIN_B2);     // turn off LED

    while(1);               // loop forever, but not sleep.
}


This is as basic as it gets. All I do is turn on the led, pause then turn off, then just do nothing.

Thoughts:

#1. If all goes well, the LED should NOT stay lite. The while will loop forever

#2. If the LED stays on, or flickers. Then something is resetting the uP

#3. If the delay_ms is >16 seconds, it also resets (ie. flicker).

#4. Really does sound like a watchdog timer issue

What can be resetting it?!

~Kam (^8*
KamPutty
Guest







WDT
PostPosted: Sat Feb 18, 2006 6:39 pm     Reply with quote

I think it's something with the Watch Dog Timer. Even thought I tell it not to use it, I think it's still using it!

Here is my now WORKING code:

Code:

#include <10F206.h>

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES NOMCLR                     //Master Clear pin: disable
#FUSES NOPROTECT                  //Code protected from reads
#use delay(clock=4000000)

main()
{
    setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
    setup_wdt(WDT_2304MS);

    while(1)
    {
        output_high(PIN_B2);    // turn on LED
        restart_wdt();
        delay_ms(100);           // lets delay.
        output_low(PIN_B2);     // turn off LED
        restart_wdt();
        delay_ms(100);           // lets delay.
    }
}


I inserted the "setup_wdt(WDT_2304MS);" and "restart_wdt();" and all works.

But I want to turn it off!

~Kam (^8*
Ttelmah
Guest







PostPosted: Sun Feb 19, 2006 3:51 am     Reply with quote

Which is why I said early on, to load the hex file into your programmer, and see how the fuses are set in here.
If I load the generated hex, into MPLAB (7.1), it shows the WDOG as off, but the code protect as on!. However it shows the configuration bytes as being at 0x1FF, which is incorrect for the 10F206!... If I load it into MachX, it correctly shows WDOG off, code protect off, and MCLR selected as an input. The fault here is in MPLAB, not in CCS, which is treating the configuration words as if they should be at address 0x1FF, and will program them incorrectly. Your programmer may have the same fault...
I suspect 7.2, will fix this.

Best Wishes
KamPutty
Guest







PostPosted: Sun Feb 19, 2006 10:59 am     Reply with quote

Ttelmah wrote:
Which is why I said early on, to load the hex file into your programmer, and see how the fuses are set in here.
If I load the generated hex, into MPLAB (7.1), it shows the WDOG as off, but the code protect as on!. However it shows the configuration bytes as being at 0x1FF, which is incorrect for the 10F206!... If I load it into MachX, it correctly shows WDOG off, code protect off, and MCLR selected as an input. The fault here is in MPLAB, not in CCS, which is treating the configuration words as if they should be at address 0x1FF, and will program them incorrectly. Your programmer may have the same fault...
I suspect 7.2, will fix this.

Best Wishes


Ahhhh! I'm gonna kill myself!
My version of MPLab is 7.3, and it shows in the Config->Configuration Bits menu the following!

Address: 0fff, Value: 0fff, Category: Watchdog Timer, Setting: ON
Address: , Value: , Category: Master Clear Enabled, Setting: Enabled
Address: , Value: , Category: Code Protect, Setting: OFF

No matter what I do with the fuses, I cannot get it to change, assuming that Config->Configuration Bits is the correct way to check.

~Kam (^8*
Stuckeymax



Joined: 15 Dec 2006
Posts: 2
Location: Atlanta, GA

View user's profile Send private message Visit poster's website

PostPosted: Tue Feb 27, 2007 2:01 pm     Reply with quote

I found something goofy in the compiler's comparator setup. I had an issue with pins misbehaving, and the processor locking up in an infinte, self-reset loop on startup (but not always; only when Vdd rise time was fast). I replaced set_comparator C instructions (and some other setup stuff) with assembly and the problem went away.
Code:


      #asm
      clrwdt               ; // This shouldn't be necessary, but...
      movwf   OSCCAL         ; // Calibrate the oscillator bits 7 through 1
      bcf      OSCCAL,0      ; // Disable Fosc/4 output to GPIO 2 by clearing bit 0


      movlw   0b11110011      ; // Disable the comparator
      movwf   CMCON0         ; //    7        6       5       4       3       2       1       0
                        ; // CMPOUTX  COUTEN/No POL/no  T0CS hot CMPoff IntRef  RefSelX  CWU Off
                        ; //     X        1       X       1      0       X       X       1
                        ; //           not             OK    OFF                      OK


      movlw   0b11000010      ; // Setup TMR0 for internal clock, with 1:8 prescale
      option               ; // No WUoC; No WPU013; TMR0 Int Clk; T0CKI edge; PSA to TMR0; 1:8


      clrf   GPIO         ; // Zero out the port prior to configuring GPIO
      movlw   0b00001000      ; // Set GPIO DDR bits in/out/out/out
      tris   GPIO         ; // Stuff the literal
      #endasm
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group