View previous topic :: View next topic |
Author |
Message |
rikotech8
Joined: 10 Dec 2011 Posts: 376 Location: Sofiq,Bulgariq
|
10F200 pull-up on inputs |
Posted: Tue Sep 01, 2015 11:59 am |
|
|
Hi everyone,
I wasn't able to make up another approach to enable pull-ups on this chip but by integrating some assembler instructions into the code. The problem is I have not much of experience with assembler, let say none.
And this is the code that is for testing the internal pull-up.
Code: |
#include <10F200.h>
#include <stdint.h>
#fuses NOWDT, NOMCLR
#use delay(clock = 4000000)
#USE FAST_IO (B)
#define LED PIN_B1
#define LED_ON output_high(LED)
#define LED_OFF output_low(LED)
#define BUTTON_IS_PRESSED input(pin_b3)
void main()
{
set_tris_b(0x08);
#ASM
CLRW
MOVLW 0x40
OPTION
CLRW
#ENDASM
while (TRUE)
{
if(BUTTON_IS_PRESSED)
LED_ON;
else
LED_OFF;
}
} |
The test covers the expected result for now. But I need to be 100% sure that the code is correct. Do you think that I succeeded to enable the pull-ups? _________________ A person who never made a mistake never tried anything new. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19369
|
|
Posted: Tue Sep 01, 2015 12:38 pm |
|
|
No. You have turned them off. The bit in the register is 0 to enable, 1 to disable... Read the data sheet.
This is why the CCS command to do this has:
setup_wdt(DISABLE_PULLUPS);
to turn them _off_. If you omit this, and use the setup_wdt function it defaults to turning them on.
So:
setup_wdt(FALSE);
actually enables the pullups. |
|
![](templates/subSilver/images/spacer.gif) |
rikotech8
Joined: 10 Dec 2011 Posts: 376 Location: Sofiq,Bulgariq
|
|
Posted: Wed Sep 02, 2015 4:44 am |
|
|
Thanks Mr. T
In order to be more flexible I am tend to use more standard instruments to
develop my code. Therefore I am still attached to the assembler code. In my perspective there was no way to come upon this approach:
without having Nostradamus skills.
Another thing I find annoying is: The datasheet says (page 14):
Quote: | (I paraphrase) The value on Power On Reset of the register OSCCAL is 1111 1110 |
Which means that INTOSC/4 is NOT applied/enabled on GP2.
Guess what I saw (while scoping) on this pin after POR (without touching the register), square pulses with period of 1uS.
Then I appended this line to initialization part of the code
Code: | *((uint8_t*)0x05) &= ~0x01; |
And finally I got what I expected. I reviewed the errata Rev.A document, but wasn't able to find related problem.
OK this was just a feed-back in case someone else encounter such a problem. All the best, and thank you again T _________________ A person who never made a mistake never tried anything new. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19369
|
|
Posted: Wed Sep 02, 2015 8:32 am |
|
|
Quote: |
without having Nostradamus skills.
|
Just read the include file for the processor.
A one second search finds the 'DISABLE_PULLUPS' instruction.
A look at the data sheet shows that the bit is a disable bit, not an enable bit, and that it is common to the register with all the watchdog controls (so explains 'why' CCS use the setup_wdt functions). So sending any other setting to the watchdog, automatically enables the pullups....
Your register five problem depends what is in the calibration value.
From the data sheet:
"In addition, a calibration instruction is programmed into
the last address of memory, which contains the calibration
value for the internal oscillator. This location is
always uncode protected, regardless of the code-protect
settings. This value is programmed as a MOVLW xx
instruction where xx is the calibration value and is
placed at the Reset vector. This will load the W register
with the calibration value upon Reset and the PC will
then roll over to the users program at address 0x000.
The user then has the option of writing the value to the
OSCCAL Register (05h) or ignoring it"
The compiler automatically writes this calibration value into the OSCCAL register. If it has bit 0 set, then the output clock will be turned on. Sounds as if possibly your chip has been erased.
Again from the data sheet:
"Note: Erasing the device will also erase the preprogrammed
internal calibration value for
the internal oscillator. The calibration
value must be read prior to erasing the
part so it can be reprogrammed correctly
later."
Since this erases to all 1's, it'd explain your behaviour..... |
|
![](templates/subSilver/images/spacer.gif) |
rikotech8
Joined: 10 Dec 2011 Posts: 376 Location: Sofiq,Bulgariq
|
|
Posted: Wed Sep 02, 2015 1:01 pm |
|
|
One more thing I find useful to be shared is:
MPLAB IDE v8.89+PICKIT3 doesn't like PIC10F200
The IDE spits some error related to calibration data.
Happily this http://www.microchip.com/forums/m500342.aspx solved the problem. _________________ A person who never made a mistake never tried anything new. |
|
![](templates/subSilver/images/spacer.gif) |
|