PDA

View Full Version : Surprising 16F628 / 20



Acetronics2
- 27th June 2008, 16:32
I tried to program a ... simple stupid blinking light ... and it doesn't work ... as it should !!!




'************************************************* *****************************
'Configuration
'************************************************* *****************************

@ __CONFIG _BODEN_ON &_CP_OFF & _PWRTE_ON & _WDT_ON & _LVP_OFF & _MCLRE_ON & _INTRC_OSC_CLKOUT

CMCON = 7
VRCON = 0

...

'************************************************* ****************************
'Initialisation des ports
'************************************************* ****************************

PORTA = 0
PORTB = 0

TRISA = %00000111
TRISB = %00000000

...

'************************************************* *****************************
oubli: ' Boucle d'arret si oubli cavalier
'************************************************* *****************************

PORTB.0 = 1
PAUSE 200
PORTB.0 = 0
PAUSE 200

GOTO Oubli



Doesn't work


But That snippet works fine :




( same as previous )

...

'************************************************* *****************************
oubli: ' Boucle d'arret si oubli cavalier
'************************************************* *****************************

HIGH PORTB.0
PAUSE 200
LOW PORTB.0
PAUSE 200

GOTO Oubli



The load on PORTB.0 is a simple LED drawing 12 mA ...

Has someone an idea ???

Alain

Jerson
- 27th June 2008, 18:08
Alain

What do you mean - Doesn't work. Can you elaborate your statement? Is the LED always on/off?
The ellipses before Oubli - is there something that modifies your TRISB in there?

When you do HIGH / LOW to a pin, PBP also writes the TRIS bit for the pin to the direction you need.

Acetronics2
- 27th June 2008, 19:51
Hi, Jerson

Halas, there are no TRIS mods in the whole program ( including PbP commands ).

Just reading 3 EEPROM locations to verify if the device is ( application ) programmed or not.

add to that a BUTTON command to verify, if EEPROM unprogrammed, if the programming jumper has been inserted ...





TRISA = %00000111
TRISB = %00000000


'************************************************* *****************************
'Lecture des valeurs en EEPROM
'************************************************* *****************************


READ 1,dureeprog
READ 2,side
READ 3,neutre

IF ( neutre <> 255 ) AND( dureeprog <> 255 ) THEN start

'************************************************* *****************************
' Vérification Présence Cavalier si premičre programmation
'************************************************* *****************************

Delay = 0
BUTTON ModProg,0,255,0,delay,1,Mesurepro

'************************************************* *****************************
oubli: ' Boucle d'arret si oubli cavalier
'************************************************* *****************************
...



as you can see, I just had cut those "unsignificant" lines.

I've also verified the ASM lines, but nothing noticeable ...



the strange thing is I had added those lines just past TRISA and TRISB, to verify PortB ( same LED load + 270 Ohms on each PortB output ) ...




'************************************************* *****************************
'Verification PORTB
'************************************************* *****************************

' FOR I = 0 to 7
'
' PORTB.0[i] = 1
' PAUSE 300
'
' NEXT I
'
' FOR I = 7 to 0 Step -1
'
' PORTB.0[i] = 0
' PAUSE 300
'
' NEXT I



and it worked well ...


I've already seen Port outputs not working , like here, but it was when driving large capacitive loads ( 3.5 µF between output and ground !!! ).

Solution had been using HIGH and LOW ... like here.


But, Here, it's the first time I see that with LEDs as loads ...

so, I know what to do ... but really don't understand why !!!

Alain

skimask
- 27th June 2008, 20:22
Read-Modify-Write issues?

Jerson
- 28th June 2008, 07:44
Alain

I'm not really sure what to make of it. What is the state of LED? On or Off?

Acetronics2
- 28th June 2008, 10:18
Hi, Jerson

PORTB.0 = 1 : Led do not work

HIGH PORTB.0 : Led works fine


Hi, Ski

I verified the ASM ... doesn't read anything at all ,here.



PORTB.0 = BSF PORTB,0

HIGH PORTB.0 = BSF PORTB,0
BSF STATUS, 5
BCF PORTB,0

**Next ASM command** MOVLW 0xC8 ( Pause duration )

BCF STATUS, 5


so, the only "surprising thing" is it writes PAUSE duration in W while addressing page 1 ... but I do not think it should cause any trouble ... I suppose it works like that not to toggle Page twice, if staying on page 1 !

I'll try the program with XTAL clock ( it's the first time I use INTRC with this snippet ...) ever has worked well till yesterday ... just to see.

Alain

Bruce
- 28th June 2008, 13:58
Hi Alain,

My guess would also be read-modify-write. Try increasing the pause time from 200 to
1000 in the first version you posted that isn't working. Does it work with the longer
pause?

sayzer
- 28th June 2008, 15:01
I had something similar.

And even tough PORTB.0 = 1 or 0 did not work, interestingly PORTB.0 = PORTB.0 ^ 1 worked.


??

paul borgmeier
- 28th June 2008, 15:23
another thought ...

try removing the LEDs and watching the pins with a scope or DMM. If no load works then add more decoupler / filter caps.

just my 1 cent

Jerson
- 28th June 2008, 16:06
Alain

Just thinking aloud. I am assuming the 16f628 / 20 in the subject means you are thinking it runs at 20MHz or is it something else? The INTOSC for the 628 is 4MHz. Perhaps you have declared 20MHz for OSC like below. Is this a possible cause?

define OSC 20

I do remember having faced a problem like this once before, but unfortunately, I cannot recall what it was and in which project. It too had to do with an LED though. All I remember is that I had to write the port twice with a delay between the 2 writes to get it to behave.

Acetronics2
- 28th June 2008, 16:27
Hi, Jerson

It's not a speed issue nor ... I intend to make them run @ 4Mhz !!! ( or so ... the RCINTOSC is somewhat aside the 4Mhz !!! )

This Pic is just ... 10% under the 4 Mhz !!! ( 136 units for a true 1500 µs pulse ).

I think we met the same issue ...


Hi, Bruce

The Pause time modifying do not change anything.

Hi, Sayzer

That's the strange thing ... just the ( let's say ) ASM command doesn't work. A signal rise and fall time issue inside the Pic ???

Hi, Paul

Signal is neat and right on the DMM ... only without the Led !


So, ... I have to try another Pic Sample to confirm !!!



BTW ... I discovered in MPLAB 8.10 programmer, If you ask for ALL Erase ... The EEPROM is NOT Erased, and you must explicitly ask for FF Writing ...

same issue in the toolbar's "Erase Flash Device" ...

to be verified for other processors ...

Alain

paul borgmeier
- 28th June 2008, 22:46
>>If no load works then add more decoupler / filter caps.

Sounds like it worked - do you have electrolytic decoupler and ceramic filter caps? Is your power clean? Have you reduced ground loops?

Strange indeed to be sensitive to 12mA load switching ....

Interested to know how it turns out