PDA

View Full Version : Can anyone see a problem with this?



George
- 9th October 2009, 02:47
I'm trying to build a synchronous motor control using a 12f629 but having problems even getting it going here's a simple code i wrote that wont work - any clues?

@ device pic12F629, INTRC_OSC_NOCLKOUT, WDT_ON, MCLR_OFF, PROTECT_OFF, BOD_ON

Define OSCCAL_1K 1
DEFINE OSC 4

CMCON = 7 'TURN COMPARITORS OFF
TRISIO = %000000 ' Set GPIO 0,1 TO INPUT, others to OUTPUT

Delay var word
MaxSpeed var word

Start:
toggle gpio.5
pause 100
goto start

Kamikaze47
- 9th October 2009, 06:31
Its probably not what's causing your problem, but to do what your comment says, the TRISIO line needs to be:

TRISIO = %00000011

What do you see when you hook up an LED to the output of GP5?

Jerson
- 9th October 2009, 06:33
First off, the TRIS is not right, but for GPIO.5, it is ok.

When you toggle a pin, you have to consider the Read-Modify-Write issue. A better way to check would be to set the pin HIGH, wait for a delay time, set the pin low, delay and loop

main
high gpio.5
pause 500
low gpio.5
pause 500
goto main

Bruce
- 9th October 2009, 22:44
Can anyone see a problem with this?
Code wise, no. It should work as expected.

If you have a read-modify-write problem with a 100mS delay between toggling an output,
then you have a hardware issue with a boat-load of external capacitance on this pin.

Remove the DEFINE OSCCAL_1K 1. If it works, then your device programmer has most likely
erased the last program memory location of this PIC that had the RETLW xx, where xx was
the factory OSCCAL calibration value being returned in the W register.

DEFINE OSCCAL_1K 1 causes PBP to issue a CALL to location 0x3FF. Once at location 0x3FF
it should RETURN with the factory OSCCAL value in W, which gets loaded into the OSCCAL
register.

If this has been erased, the CALL causes a nasty loop from 0x3FF right back to 0x00, since
the RETLW instruction + the xx it should return has been erased.

This causes your program to loop continuously from 0x3FF back to 0, making it appear that
nothing is working.