View previous topic :: View next topic |
Author |
Message |
eem2am
Joined: 18 Jul 2012 Posts: 21
|
PIC10F200 code not working... |
Posted: Wed Jul 25, 2012 5:55 am |
|
|
Hello,
do you know why this code does not work.?
all it does (should do) is take GP0 high and low with duty cycle = 50% and period = 20ms.
But GP0 is just always low
Code: | #include <10F200.h>
#use standard_io(B)
#use delay(clock=4000000)
#fuses NOWDT,NOPROTECT, NOMCLR
#define PIN_TRIGGER PIN_B0 // Output high to trigger
#define PIN_SYNC PIN_B1 // Output low to send sync pulse; Input when listen for sync pulse
#define PIN_PHASE PIN_B2 // Input low flashes IN sync; Input high = anti sync;
// Low to high at 50Hz means AC input, so flash in sync.
#define PIN_FPM PIN_B3 // Input high = 75FPM; Input low = 60FPM
//Remember to disable internal pullups
//Remember to enable watchdog and add clrwdt instuctions
//Remember to calibrate the internal oscillator.
//Are they outputs or inputs by default.?...or are they high impedance by default?
//can you set a port to high Z by just reading from it?
//STATUS REGISTER, Option register,
//M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M
//VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
// Main program starts here
void main(void)
{
//Disable port B pullups
// port_b_pullups(FALSE);
// setup_counters(RTCC_INTERNAL, WDT_2304MS);
//ENSURE TIGGER OUTPUT IS LOW
output_bit(PIN_TRIGGER, 0);
output_bit(PIN_SYNC, 0);
output_bit(PIN_FPM, 0);
output_bit(PIN_PHASE, 0);
delay_ms(800);
while(1){
output_bit(PIN_TRIGGER,1); //SEND TRIGGER PULSE
delay_ms(10);
output_bit(PIN_TRIGGER,0);
delay_ms(10);
}
} // end of main
//M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M M
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Wed Jul 25, 2012 6:22 am |
|
|
The code looks fine to me. How do you measure the output? 10ms will be too fast for a Digital Voltage Meter and also a blinking LED will be too fast for the eye to see.
A few minor details:
- When posting code, make it as short as possible. See below 20 lines versus your 59.
- The sequence of the first three lines in my programs is always #include, #fuses and then #delay. Just because there might some dependencies in the sequence (I don't trust CCS in this from bad experiences).
- Normally I recommend to use standard_io in CCS programs but in your tiny PIC10 you can save a few precious bytes by using fast_io.
Code: | #include <10F200.h>
#fuses NOWDT,NOPROTECT, NOMCLR
#use delay(clock=4000000)
#use fast_io(B)
#define PIN_TRIGGER PIN_B0 // Output high to trigger
void main(void)
{
set_tris_B(0b00001100); // B0 and B1 as output, B3 and B4 as input
while(1)
{
output_bit(PIN_TRIGGER,1); //SEND TRIGGER PULSE
delay_ms(500); // increased to 500ms for easier testing
output_bit(PIN_TRIGGER,0);
delay_ms(500);
}
}
|
|
|
|
eem2am
Joined: 18 Jul 2012 Posts: 21
|
|
Posted: Wed Jul 25, 2012 8:00 am |
|
|
thanks, ill try your code, but i notice you don't have a setup counters instruction?
the pic pins simply have just 47K pullups on them.....i wonder if this is too big and I'm getting noise in the pins? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19513
|
|
Posted: Wed Jul 25, 2012 8:35 am |
|
|
Neither do you (it's remmed out). However it shouldn't be needed unless you want to use the timer, or the watchdog.
On the resistors, depends - how long are the wires attached?. What noise sources are nearby?.
You can run a pin with 1MR+ as pullup's, in a low noise environment.
Best Wishes |
|
|
eem2am
Joined: 18 Jul 2012 Posts: 21
|
|
Posted: Wed Jul 25, 2012 8:53 am |
|
|
Hello,
We still cannot get our code to work.
We did it with fast io like your code and we got a 50KHz square wave on GP0 GP1 GP2 and high on GP3
We then changed to standard io and got a 20KHz square wave.....
..at least it was a square wave but our frequency was set too 10Hz, not thousands of Hertz
Can you find a problem with the code?
Is their a bug with PIC10F200?
Code: | #include <10F200.H>
#use delay(clock=4000000)
#fuses NOWDT,NOPROTECT,NOMCLR
#use standard_io(B)
#define PIN_TRIGGER PIN_B0
#define PIN_SYNC PIN_B1
#define PIN_PHASE PIN_B2
#define PIN_FPM PIN_B3
// Main program
void main(void)
{
setup_counters(rtcc_internal, rtcc_div_2);
while(TRUE){
output_high(PIN_PHASE); output_high(PIN_SYNC); output_high(PIN_TRIGGER); output_high(PIN_FPM);
delay_ms(50);
output_low(PIN_PHASE); output_low(PIN_SYNC); output_low(PIN_TRIGGER); output_low(PIN_FPM);
delay_ms(50);
}
} // end of main
^^ |
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19513
|
|
Posted: Wed Jul 25, 2012 9:11 am |
|
|
OK.
The difference in speed is the difference between the I/O, with the extra instructions needed for standard IO.
However the timings, I think are a known issue with CCS, on some compiler versions with these chips (PIC10/12). There were some threads here a while ago, about the delays not working properly on these. If I remember correctly, on these chips delays over an int8, wouldn't work (at all...).
So try with delay_ms(255) and see what happens.
Best Wishes |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Wed Jul 25, 2012 9:19 am |
|
|
Back to the basics:
ALWAYS POST YOUR COMPILER VERSION !!!!
In a previous post you mentioned you were using a compiler manual from 2003 because you have to use an old compiler version for backwards compatibility. But as far as I can see you never mentioned the actual version number you are using. This makes it impossible for us to reproduce your problem.
Besides all that, I don't want to give support on a 9 years old compiler when you can get a recent CCS PCB version for free with a download of MPLAB.
The reason for backwards compatiblity makes no sense to me when we are talking about a tiny program of maximum 256 bytes ROM code. Also very likely the compiler contains bugs and we are now wasting a lot of time to work around a bug that has long since been fixed.
Just to convince your employer I would download the free CCS demo version from the website. Test with this new version and see if it solves your problem. |
|
|
eem2am
Joined: 18 Jul 2012 Posts: 21
|
|
Posted: Wed Jul 25, 2012 9:49 am |
|
|
OK but our old code is written with old compiler so we need to use that
by the way we wrote it in assembler and it works on the pic in the hardware............
Code: |
;vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
list p=10F200
#include <p10F200.inc>
__CONFIG _MCLRE_OFF & _CP_OFF & _WDT_OFF
;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
counter EQU 0x14
counter1 EQU 0x15
;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ORG 0xFF
ORG 0x000
movwf OSCCAL
start
movlw 0xC7
option
movlw 0b00000000
tris GPIO
nop
here
bsf GPIO,0
bsf GPIO,1
bsf GPIO,2
bsf GPIO,3
call delay_10ms
bcf GPIO,0
bcf GPIO,1
bcf GPIO,2
bcf GPIO,3
call delay_10ms
goto here
delay_10ms
movlw 0x0D
movwf counter1
ccc
clrwdt
movlw 0xFF
movwf counter
ddd
decfsz counter,1
goto ddd
decfsz counter1,1
goto ccc
retlw 0x00
END |
|
|
|
eem2am
Joined: 18 Jul 2012 Posts: 21
|
|
Posted: Wed Jul 25, 2012 12:26 pm |
|
|
OK thanks i will get the new CCS PCB version, but how will MPLAB (v8.60) know where to get the PCB compiler from?
...surely it will keep getting the old compiler which is stored in the "microchip" folder in the "Program files" folder?
By the way, are you suggesting that the (old) compiler version that we are using may need a patch to deal with the problem that we are having with the delay_ms(10); instruction ?
...and that because this compiler is so old, this patch will no longer be available? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Jul 25, 2012 4:43 pm |
|
|
Quote: | But how will MPLAB (v8.60) know where to get the PCB compiler from?
|
Just go to the MPLAB Project Menu, and then to the "Set Language Tool
Locations" menu. Then click on the "+" next to CCS C Compiler to
expand it. Then get down to "Executables" and select it. Then click
Browse button and navigate to this directory:
Quote: | c:\Program Files\Microchip\Third Party |
Then go to the PICC directory in there, and select the ccsc.exe file.
That's the executable for the compiler, for the version that's included
with MPLAB. |
|
|
eem2am
Joined: 18 Jul 2012 Posts: 21
|
|
Posted: Wed Jul 25, 2012 11:20 pm |
|
|
thanks,
but due to compatibility reasons, we still use MPLAB V8.60, so in that third party folder is the old ccs compiler |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Jul 26, 2012 1:47 pm |
|
|
I don't see how we can help you, because you are so concerned with
using old tools. What difference does MPLAB 8.86 vs. 8.60 have with
respect to the compiler ? None really. The compiler compiles the code.
The compiler is the important component. It makes the HEX file. MPLAB
is just the IDE that makes the compiler easy to use, and possibly it's also
your programmer software.
My advice is to upgrade to MPLAB 8.86 and use the PCB compiler that
comes with that version. You will probably be able to make your program
work with those tools. Then if you are concerned about it, carefully
review the .LST file. Print it in both standard and Symbolic mode.
Check all the register addresses, and look at the code for the internal
functions to make sure it looks correct. Compare it to the .LST file
made by your older version of the compiler. |
|
|
|