View previous topic :: View next topic |
Author |
Message |
ralpok
Joined: 21 Dec 2005 Posts: 25
|
Trouble getting PIC10f320 to run |
Posted: Sat Feb 09, 2013 12:57 pm |
|
|
I have a project I have started with the PIC10f320 micro controller. I want to just get a simple program running toggling PIN4 (GP2) on the device. As far as I can tell I am unable to even get this running and since this chip/compiler doesn't support debugging I am a bit lost. The program I have tried to run is:
I am running Win 7:
CCS Studio: PCWHD 4.134
Code: |
#case
#include <10f320.h>
#device ADC=10
#fuses NOWDT
#use delay (internal=8000000)
void main()
{
int8 velocity[10];
int16 avgVelocity = 0;
int ndx = 0;
delay_ms(2000);
set_tris_a(0x00);
output_high(PIN_A2);
while (1)
{
output_toggle(PIN_A2);
delay_ms(10);
}
}
|
Any thoughts people have on why I can't get the pin to toggle would be appreciated. I even disconnected it from anything else on my circuit board to make sure something wasn't holding it low. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9245 Location: Greensville,Ontario
|
|
Posted: Sat Feb 09, 2013 1:42 pm |
|
|
I don't use that PIC but ...
1) check to see what other peripherals can also use that pin. Typically the
ADC will default to being 'attached'. Also comparitors, UART, MSSP,etc.
2) What pullup resistor are you using? Some PIC pins are open drain and need a load..
3) Is that pin configurable as an OUTPUT ? While most are, some aren't all depends on the PIC
Check the datasheet it'll soon tell you the defaults for the I/O pins as well as functionality(I/O, I only,O only)
Also...be sure to have 'release' selected as the build configuration within MPLAB.
hth
jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19549
|
|
Posted: Sat Feb 09, 2013 3:52 pm |
|
|
On the 10F320, A0 to 2, wake up as analog. This overrides port I/O. You need to turn this off.
From the data sheet:
"Note: The ANSELA bits default to the Analog
mode after Reset. To use any pins as
digital general purpose or peripheral
inputs, the corresponding ANSEL bits
must be initialized to ‘0’ by user software."
Best Wishes |
|
|
ralpok
Joined: 21 Dec 2005 Posts: 25
|
|
Posted: Tue Feb 19, 2013 10:47 am |
|
|
Thank you guys for all your help. Your advice and input got me heading in the correct direction and I was able to pretty quickly get this up and running. In the end I had to manually set the PORTA, LATA, ANSELA, and TRISA registers in order to get it working. I followed the assembly that was in the datasheet and this seems to work. I can probably do this using the CCS Libraries in some way but I am not sure how. In case anybody else is interested I will post my working code.
Code: |
#case
#include <10f320.h>
#device ADC=10
#fuses NOWDT, INTRC
#use delay (internal=8000000)
#use standard_io(A)
#byte PORTA = 0x05
#byte LATA = 0x07
#byte ANSELA = 0x08
#byte TRISA = 0x06
void main()
{
int8 velocity[10];
int16 avgVelocity = 0;
int ndx = 0;
delay_ms(2000);
PORTA = 0x00;
LATA = 0x00;
ANSELA = 0x00;
TRISA = 0x00;
output_high(PIN_A2);
while (1)
{
output_low(PIN_A2);
delay_ms(10);
output_high(PIN_A2);
delay_ms(10);
}
}
|
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19549
|
|
Posted: Tue Feb 19, 2013 1:16 pm |
|
|
1) TRIS is set for you.
2) PORT/LAT registers are set for you.
3) setup_adc_ports.....
Best Wishes |
|
|
stinky
Joined: 05 Mar 2012 Posts: 99 Location: Central Illinois
|
|
Posted: Wed Mar 06, 2013 10:37 pm |
|
|
I'd suspect that the reason your later code works and the first code didn't is the following.
original code:
updated code:
Code: | #fuses NOWDT, INTRC |
Without "INTRC" specified it defaulted to looking for an external clock. If you didn't have that clock, no instructions were executed at run time. And no pin was toggled. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Mar 06, 2013 11:09 pm |
|
|
Look at the Fuses in the .LST file for his first program:
Quote: | Configuration Fuses:
Word 1: 3EC6 INTRC BROWNOUT NOWDT PUT MCLR NOPROTECT NOLVP LPBOR BORV19 NOWRT NODEBUG |
When the compiler sees the "internal" keyword in the #use delay()
statement, it enables the INTRC fuse:
Quote: | #case
#include <10f320.h>
#device ADC=10
#fuses NOWDT
#use delay (internal=8000000) |
However, I personally prefer to specify it in the #fuses statement and
not in the #use delay(). |
|
|
|