PDA

View Full Version : 16F777 resetting - at seemingly random times



orjon1
- 24th June 2011, 13:58
Interrupts? WDT?

I've the PIC fading through the spectrum with RGB LED strips connected to the three PWM pins. Yet something keeps resetting the program. The timing of the resets is not consistent - at lease once every 2 mins, sometimes after 30 seconds.

I've turned off the WDT and disabled all interupts - also set all pins to outputs.. still resetting. Have I perhaps done this incorrectly, or missed something?


Any other ideas what could cause this?



@ DEVICE PIC16F777, INTRC_OSC_NOCLKOUT, WDT_OFF

DEFINE OSC 8

OSCCON = %01110010 'see data sheet for INTRC speed setting
ADCON1 = 15 ' All I/O pins digital
INTCON.7 = 0 ' tunr off all interuppts

TRISA = %00000000
TRISB = %00000000
TRISC = %00000000
TRISD = %00000000
TRISE = %00000000


' Set CCPx pins to outputs
TRISC.2=0 ' CCP1 output
TRISC.1=0 ' CCP2 output (could also be assigned to RB3)
TRISB.5=0 ' CCP3 output

' Set CCP modules to PWM mode
CCP1CON = %00001100 ' Mode select = PWM
CCP2CON = %00001100 ' Mode select = PWM
CCP3CON = %00001100 ' Mode select = PWM

' Set period up for 1.22kHz PWM freq
PR2 = $FF

pie2.0 = 0
pie2.1 = 0
pie1.2 = 0

' Set TMR2 up for 1:16 prescale & turn it on
T2CON = %00000110 ' TMR2 ON 1:16 prescale

' Word vars for 10-bit value of each PWM duty cycle
DutyR VAR WORD ' Channel #1
DutyG VAR WORD ' #2
DutyB VAR WORD ' #3


cyclespeed var byte
cyclemax var word


cyclespeed = 10
cyclemax = 900

gosub cyclestart 'INTRO SEQUENCE

main
ChangeGreenUp:
Repeat
DutyG = Dutyg + 1
gosub colourset
pause cyclespeed
until dutyg = cyclemax

ChangeRedDown:
Repeat
Dutyr = Dutyr - 1
gosub colourset
pause cyclespeed
until dutyr = 0

ChangeBlueUp:
Repeat
Dutyb = Dutyb + 1
gosub colourset
pause cyclespeed
until dutyb = cyclemax

ChangeGreenDown:
Repeat
Dutyg = Dutyg - 1
gosub colourset
pause cyclespeed
until dutyg = 0

ChangeRedUp:
Repeat
Dutyr = Dutyr + 1
gosub colourset
pause cyclespeed
until dutyr = cyclemax

ChangeBlueDown:
Repeat
Dutyb = Dutyb - 1
gosub colourset
pause cyclespeed
until dutyb = 0

goto main
'---------------------------------------------------------------------------
colourset:
CCP1CON.4 = Dutyg.0 ' Setup 10-bit duty cycle as
CCP1CON.5 = Dutyg.1 ' a 10-bit word
CCPR1L = Dutyg >> 2

CCP2CON.4 = DutyR.0
CCP2CON.5 = DutyR.1
CCPR2L = Dutyr >> 2

CCP3CON.4 = Dutyb.0
CCP3CON.5 = Dutyb.1
CCPR3L = Dutyb >> 2
return
'---------------------------------------------------------------------------
cyclestart:
dutyR = cyclemax
dutyg = 0
dutyb = 0
gosub colourset
PAUSE 500

dutyR = 0
dutyg = cyclemax
dutyb = 0
gosub colourset
PAUSE 500

dutyR = 0
dutyg = 0
dutyb = cyclemax
gosub colourset
PAUSE 500

dutyR = cyclemax
dutyg = 0
dutyb = 0
gosub colourset
return
'---------------------------------------------------------------------------
END


Many Thanks!

Jumper
- 24th June 2011, 14:20
Are you sure you habe a strong and noice free powersupply. Do you power the LED and the PIC from the same supply? Maybe there is not just enough power when you have all 3 LEDs on at maxpower to make white.

Is BOR turned off or at least set to its lowest setting?

Are the LED drivven inside their performance (current limiting resistors)?

orjon1
- 24th June 2011, 15:04
I have tried three power supplies - Using one for circuit and one for LEDS, and also using the same supply split with a voltage regulator for the PIC circuit. The LED supply is a hefty (and expense!) 12v 8.5 amp supply that should be more than adequate to power 10meters of 5050 smd RGB leds;

36watts per 5 meters - From Manufacturer
Thus 10m = 72 watts
72 / 12v = 6 amp.
I believe that calculation is correct. No smoke yet anyway...

On your suggestion, I have set PCON.2=0 (BOR = OFF) and the problem persists.

Any other ideas? I read something about PCL tables...

Many Thanks!





The LED strips have their own resistors. As I am cycling through the colours - there are only ever two colours on at the same time (interesting spectral information!).

orjon1
- 24th June 2011, 15:58
here is the circuit;

5706

LinkMTech
- 24th June 2011, 16:52
Try adding 1.0uF caps to the input and output of the 5V regulator as well.
I would make sure the 4.7K pullup on the MCLR line has a solid connection. A MCLR left floating would also cause intermittent resets.
Or just disable the MCLR function (MCLR_OFF, if I remember correctly) just to be sure some unseen noise spikes are not triggering the uC reset.

shahidali55
- 24th June 2011, 17:02
Try 47ohm resistor between PWM pins and mosfet gate

mister_e
- 24th June 2011, 17:27
BOTH Vdd and BOTH Vss NEED to be connected.

orjon1
- 24th June 2011, 17:34
BOTH Vdd and Vss? Wow, that's new - I'm surprised my other projects worked at all..

Will start with that and the MCLR and see how it goes.

Thank you all.

orjon1
- 24th June 2011, 18:40
Working perfectly!

Changes made,
MCLR OFF
47ohms resistors to MOSFET's
both Vdd and Vss's connected

Have not added the cap's due to space constraints - but will do that if it plays up again.

Thank you all again.
Orjon.

Archangel
- 25th June 2011, 02:47
I thought so but was not sure enough to mention it, thanks Steve.