PDA

View Full Version : Unstable 18f458



pkoliver
- 1st October 2011, 12:19
Hi
I am migrating from 16f887 to 18f458 in a motor control application. both chips work my dev board (labx 2) and also in my prototype rig
until the motor is connected. then the 16f is ok but the 18f has random resets will run sometimes for 20 seconds others 1 second.
I have determined that the problem is complete reset. I also checked with oscilloscope vss is good and no noise on vdd. Lower current to the motor seemed to lengthen run time. Very frustrating. What things can cause the pic to reset.
regards Paul

mackrackit
- 1st October 2011, 13:34
A voltage drop could cause a reset. Are the motors using the same power supply as the MCU?
How are the configs set for the 18F?

pkoliver
- 2nd October 2011, 12:37
Thanks for the reply Mackrachit
The only change to config was to change to HS in the inc file. The brown out is set to enable and 2 v. I tested with brown out disable with no effect. Testing for power drops shows no problem. I use a !2 v supply from a bench supply and a 7805 5v reg. A further problem has occurred on one occasion. The eeprom data for approx 32 registers changed to 00. See photo of my prototype set up. The bipolar stepper drivers are close to the pic. Are 18f very delicate compared to 16f
regarding em interference. Please treat my as pic novice as only been playing for 12mths (lots of fun though)





6019

cncmachineguy
- 2nd October 2011, 14:42
If you have an scope, watch the ground for spikes. I expected to see some caps in the area of 47uF but cant make them out on your board. Stepper drives are NOISEY!!! You may be getting a spike on ground enough to cause the pic to reset.

mackrackit
- 2nd October 2011, 14:46
Yup, what he said.
A sprinkling of caps where ever you can fit them in. Most important have them as near to the MCU VSSs and VDDs as you can.

pkoliver
- 3rd October 2011, 11:20
Hi
see picture with suggested caps. thanks both for the advice. Now working fine. I did see the spikes on ground and moved my vss connection point to the ov pin on the 7805 before my post and had a small improvement. My scope showed this point to be clean.(it is a PC based scope. keep my good scope at work. May not be quick enough to trigger on the spike). But probably not clean enough. You can only find out what you don't know by doing something first and apparently circuit design isn't my strong point.



cncmachineryguy How are you involved in with cnc. I make my living with cnc machines. look up my business at www.abcoprecision.com.au

now to get the 40mhz osc to work


6027

mackrackit
- 3rd October 2011, 11:41
now to get the 40mhz osc to work

Use a 10MHz crystal or resonator then set the config to HS4.

pedja089
- 3rd October 2011, 12:39
It would be better to use 100nF ceramic cap. They have much better(10X lower or even more ) ESR than elco.

pkoliver
- 3rd October 2011, 13:26
hi

any problem using both 47uf and 100nf.

also now am losing some data when loading map data to codespace from serial ( max 232) . going to bed . late here in oz. will test in lab-x2 to see if serial in is ok tomorrow and then chase down my proto board probs.
good nite

regards Paul

mackrackit
- 3rd October 2011, 15:37
also now am losing some data when loading map data to codespace from serial
You need to post the code and clarify some.

cncmachineguy
- 3rd October 2011, 16:08
Paul, Can you please post the drive chip you are using for the steppers? I can't quite make out the part number. I think the 47uF caps should be as close to those chips as possible but would like to double check the datasheet.

Side note - I have a small contract job shop. 4 VMC's and a lathe. But my true love is building machines and controlling them. My user name is a left over from a long time ago in another forum, so I just use it now for easy remembering to me. :)

pkoliver
- 4th October 2011, 13:24
Hi again

The stepper driver ic L298n with L297 controller ic.

When upload if maps to pic method is as follows.
1 send numeric value 1 to select case 1 load map data
2 pc waits to receive "R" (pic ready)
3 send first packet "AxxxxBxxxx" A= address B= data
4 write data to eeprom or code space depending if A value < 128
5 send "s" to PC
6 wait for next packet
7 if "A9999" received end of data transfer

Sometimes upload is fine.
There is 13 blocks of 256 words that make up the map data and when I view the pic memory I can see areas with rows of zeros and some 00001 and 00002 where a value of 55 should be. this fail area is for 4 memory rows and then comes good. When upload of map is in progress the stepper driver is set to disable and .12 amp of draw only from power supply in this state so noise at this time is unlikely.


see picture taken from meProg The row with 11111 is a partition only and npt read. Below that the values should be progressively larger than the 45 values that are correct.

Beginning to suspect the usb to serial adapter. This is difficult to see because if the data string is not AxxxxBxxxx then error occures. so the error is only in the values after B as the correct addresses are written . It is as if the charge pump runs out in the pic and then recovers. Also the defective area is mainly in a similar area. Tricky hey


6033








'-------------Main Code------------
DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 24h
DEFINE HSER_BAUD 76800
DEFINE HSER_EVEN 1
DEFINE OSC 20


INTCON2.7=0 ' Enable PORTB pull-ups 18f458


TRISB = 110000
PORTB = 000001


loadlamp1 var word
loadlamp2 var word
mapflag var byte
data1 VAR word
location VAR word
computercontrol var byte
computerpos VAR word
connect var byte


'------------------------------------------------------------------------------------------------------
mainloop:


if RCSTA.1 then ' Overrun error? used to reset input ready to recieve
RCSTA.4=0 ' clear it
RCSTA.4=1
endif


if PIR1.5 then gosub loaddata 'if a chaeacter has arived at serial in the PIR1.5 will = 1


goto mainloop:


'------------------------------------------------------------------------------------------------
Loaddata:

hserin [dec1 data1] 'read case number from pc 1 = load 2 = computer control 4 = connection extablished 5 = disconnect
select case data1


case 1
loadlamp1 = 0
loadlamp2 = 6
HSEROUT ["R"] 'pic ready to recieve


Load2:
HSERIN 5000,TimeOut2,[WAIT("A"),hex4 location,WAIT("B"),hex4 data1] 'if next packet not recieved in 5 sec then go timeout 2


loadlamp1 = loadlamp1 + 1 'led flash while data transfer in progress
if loadlamp1 > loadlamp2 then PORTB=PORTB << 1
if loadlamp1 > loadlamp2 then loadlamp2 = loadlamp1 + 6
IF PORTB.3 THEN PORTB = 000001

if location = 9999 then goto TimeOut2 'when A9999B0000 sent from pc data transfer finished
if location > 128 then goto cs 'codespace addresses are always greater than 128
write location , data1.lowbyte
write location+128 , data1.highbyte
HSEROUT ["S"] 'please send next data packet
GOTO Load2:

cs:
Writecode location ,data1
HSEROUT ["S"] 'please send next data packet
GOTO Load2


TimeOut2:
if location = 9999 then
HSEROUT ["Recieve ok"]
else
HSEROUT ["F"] 'fail load set to pc
endif
HSERIN 20,TimeOut3,[WAIT("recieve nill")] 'this is needed to final clear PIR1.5 and stops main loop jump to loaddata
TimeOut3:
PORTB = 000001
RETURN


case 2
HSEROUT ["R"]
computercontrol=1
HSERIN 5000,TimeOut2,[WAIT("P"),dec3 computerpos]
location = 9999
goto TimeOut2


case 3
HSEROUT ["R"]
computercontrol=0
location = 9999
goto TimeOut2


case 4
HSEROUT ["C"]
connect=1
location = 9999
goto TimeOut2


case 5
HSEROUT ["D"]
connect=0
location = 9999
goto TimeOut2
end select
return




end