PDA

View Full Version : PIC 16f628A refusing to work



Davidmarks
- 27th February 2011, 13:35
I think I'm doing something daft again ! I have built a circuit by Bill Sherman which operates a "perpetual" pendulum. The circuit specifies the 16 F 628. I have used the 16f628A the circuit should be run at 20 mhz. Since it shows no Capacitors withe crystal I have installed 33 pf. I have also modified the code to 16F628A and the chip seems to be programming Ok but does not appear to run ! Comments or help would be appreciated. I attach the circuit and the asm
['************************************************* ***************
'* Name : picpend.BAS *
'* Author : Bill Sherman *
'* Notice : Copyright (c) 2004 Bill Sherman *
'* : All Rights Reserved *
'* Date : 6/06/04 *
'* Version : 1.0 *
'* Notes : *
'* : *
'************************************************* ***************

'single coil design
'move pulse to pin 17, change A0 to output
'adjustable pulse time
'mode button to read pulse lenght in millisec
'up down button for millisec on time 1 to 20 msec
@ device pic16f628a, hs_osc, wdt_off, mclr_on, protect_off ,pwrt_on, bod_on, lvp_off, cpd_off


define osc 20

CMCON=%00100101
VRCON=%11110001

sense var CMCON.7 'pin 18
pulse var porta.0 'pin 17
kick var byte
n var byte
up var porta.3
dn var porta.5
mode var porta.4

output porta.0
input porta.3
input porta.5
input porta.4

setup:
pause 1000
read 0,kick
if kick > 20 then
kick = 20
endif

if kick < 1 then
kick = 1
endif

main:
if up = 0 then kickup
if dn = 0 then kickdn
if mode = 0 then modedetect
if sense = 1 then kickcoil
goto main

kickup:
kick = kick + 1
if kick > 20 then
kick = 20
endif

output porta.4
low porta.4
pause 200
high porta.4

waitup:
if up = 0 then waitup
input porta.4
goto main

kickdn:
kick = kick - 1
if kick < 1 then
kick = 1
endif

output porta.4
low porta.4
pause 200
high porta.4

waitdn:
if dn = 0 then waitdn
input porta.4
goto main

modedetect:
gosub countkick
pause 1000
write 0,kick
output porta.4
low porta.4
pause 1000
high porta.4
input porta.4
goto main

kickcoil:
low pulse
pause kick
high pulse
pause 100
goto main

countkick:
pause 1000
for n= 1 to kick
output porta.4
low porta.4
pause 100
high porta.4
pause 300
next n
input porta.4
return

goto main

end


]

Jerson
- 27th February 2011, 14:16
Try this



@ device pic16f628a, hs_osc, wdt_off, mclr_off, protect_off ,pwrt_on, bod_on, lvp_off, cpd_off


This is needed since MCLR is used as an input. You may also change HS_OSC to XT_OSC since HS is used for resonators and XT for a crystal.

Davidmarks
- 27th February 2011, 16:21
Hi, Thanks for quick reply ! I have tried the changes you suggest but still no signs of life. I should perhaps have mentioned that I am using a Pickit 2 to proram the 16f628a and have it directly connected to pins 12,13,14 and 4. Having prorammed it ( and there is a hex file in there if I read it) I remove the Pic Kit and connect and external supply as the coil would draw more current than the pic Kit would be happy with. Can't help thinking I am doing something seriously dumb here (not for the first time !