View previous topic :: View next topic |
Author |
Message |
stoyanoff
Joined: 20 Jul 2011 Posts: 375
|
Problem with 10F200 |
Posted: Sun Apr 21, 2013 6:46 am |
|
|
Hi, everyone! I have a problem with PIC10F200. The controller doesn`t output signals on it`s pins. Here is my code:
Code: |
#include <10F200.h>
#FUSES NOWDT
#use delay(clock=4M)
void main()
{
output_drive(PIN_B2);
while(1)
{
output_high(PIN_B2);
delay_ms(1000);
output_low(PIN_B2);
delay_ms(1000);
}
}
|
And when I run this I have 1.6V on pin B2, but the Vcc is 4.4V(from PIC Kit 3)
Can you tell me what I`m doing wrong??
Thanks! |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
|
Posted: Sun Apr 21, 2013 6:58 am |
|
|
Look at the order of precedence on datasheet page 25 and you will see the pin is
used for multiple functions. I/O is the lowest order with TOCK1 and FOSC
being higher. This means those options must be disabled before the pin will
work for digital IO _________________ Google and Forum Search are some of your best tools!!!! |
|
|
stoyanoff
Joined: 20 Jul 2011 Posts: 375
|
|
Posted: Sun Apr 21, 2013 10:15 am |
|
|
OK! I far as I understood I have to set OPTION_REG`s bit 5 to 1 and OSCCAL register`s bit 0 to 0.
In Special Function Registers I set OPTION_REG to 0xFF and OSCCAL to FE and again I have 1.6V on pin B2.
How do I have to set this values? Am I doing it wrong? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19538
|
|
Posted: Sun Apr 21, 2013 11:16 am |
|
|
You almost never have to touch registers directly in CCS.
what does setup_timer_0(T0_INTERNAL);.... do?.
FOSC4 is disabled by default.
Best Wishes |
|
|
stoyanoff
Joined: 20 Jul 2011 Posts: 375
|
|
Posted: Sun Apr 21, 2013 1:09 pm |
|
|
Sorry, but I can`t make it! This is my new program, but this time I have 0 volts on B2:
Code: |
#include <10f200.h>
#Fuses NOWDT
#use delay(clock=4M)
void main()
{
setup_timer_0(T0_INTERNAL);
output_drive(PIN_B2);
output_high(PIN_B2);
while(1);
}
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Apr 21, 2013 2:41 pm |
|
|
If you want pin GP2 (PIN_B2) to be an i/o pin, you need to clear the
T0CS bit in the OPTION register. See the example below:
Code: |
#include <10F200.h>
#fuses NOWDT, NOMCLR
#use delay(clock=4M)
#define set_options(value) {#ASM \
MOVLW value \
OPTION \
#ENDASM}
//==========================================
void main()
{
set_options(0xDF);
while(1);
} |
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19538
|
|
Posted: Mon Apr 22, 2013 1:16 am |
|
|
The compiler does that for you, unless you have an old version.
Code: |
.................... void main()
.................... {
0002: MOVLW DF
0003: OPTION
|
First two lines of the generated assembler.
The poster hasn't said what compiler version they have. I'd suspect a rather old one....
Best Wishes |
|
|
stoyanoff
Joined: 20 Jul 2011 Posts: 375
|
|
|
stinky
Joined: 05 Mar 2012 Posts: 99 Location: Central Illinois
|
|
Posted: Thu Apr 25, 2013 8:58 am |
|
|
Try adding a 0.1uf decoupling capp to the VDD line of the pic?
I've been bit in the butt by that causing odd behavior.
Also, my compiler version doesn't support this part so I cannot confirm, but does
Code: | #use delay(clock=4M) |
produce the desired setting? Your schematic doesn't show an external crystal so I'd assume you want the internal r/c setting. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19538
|
|
Posted: Thu Apr 25, 2013 9:14 am |
|
|
The 10F20x chips _only_ operate with the internal oscillator. To save pins. Quote from data sheet:
"The PIC10F200/202/204/206 devices are offered with
Internal Oscillator mode only."
Makes oscillator selection rather easy!....
No possibility of an external crystal.
Agree wholeheartedly on the capacitor. Strange behaviours of all sorts can result if there is not adequate decoupling. Also don't think 'bigger is better' here, and say 'got 470uF on the supply'. Needs to be a capacitor with good HF performance (most electrolytic's do not have good HF perfromance), close to the chip.
Best Wishes |
|
|
|