PDA

View Full Version : Slow starting up



lerameur
- 9th May 2013, 04:26
hello,

Not sure when I should put this...
I have a program working 100% on the breadboard.
I made a prototype board (soldering) , use the same chip and put in the socket of the prototype board. guess what.. its takes about 8 to 40 seconds to get running and showing values on the LCD..
..sometimes it will show only half the LCD screen for a couple of seconds then will show all what is suppose to show.
First, it should take just 1 second to show the info on the LCD
Second, like I said its the same chip.. put it back on the breadboard and it works.... Same value 10k MCLR,

Anybody had this issue before ???
I 'd rather it not be working instead of this...

K

lerameur
- 9th May 2013, 06:20
I will post the code, because I think that might be issue here... I used another PIC from a previous project and its working ..

INCLUDE "modedefs.bas" 'Includes supoprt for PicBasic language

OSCCON = %01100000 '4 Mhz
DEFINE OSC 4

CMCON = 7 : ADCON1 = 7
DEFINE LCD_DREG PORTB ' Set LCD Data port
DEFINE LCD_DBIT 4 ' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_RSREG PORTA ' Set LCD Register Select port
DEFINE LCD_RSBIT 2 ' Set LCD Register Select bit
DEFINE LCD_EREG PORTA ' Set LCD Enable port
DEFINE LCD_EBIT 3 ' Set LCD Enable bit
DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
DEFINE LCD_LINES 2 ' Set number of lines on LCD
DEFINE LCD_COMMANDUS 2500
DEFINE LCD_DATAUS 250
DEFINE CHAR_PACING 2000
pause 1500


' Define ADCIN parameters
Define ADC_BITS 10 ' Set number of bits in result
Define ADC_CLOCK 3 ' Set clock source (3=rc)
Define ADC_SAMPLEUS 50 ' Set sampling time in uS

DEFINE CCP1_REG PORTB
DEFINE CCP1_BIT 0
ANSEL = %00000010 ' set AN1 as analog, others to digital

ADCON1 = %10000010 ' Set PORTA analog for ten bit ADC
'ADCON0 = %00000001 ' Configure and turn on A/D Module

TRISB = %01000010
TRISA = %00000111

DutyCycle var word
Frequency var word

Mainloop:

ADCON0.2 = 1 'Start Conversion
pause 20
ADCIN 0, DutyCycle 'Read channel PORTA.0 Duty Cycle
ADCIN 1, Frequency 'Read channel PORTA.1 Frequency
Frequency = Frequency + 245
DutyCycle = DutyCycle/4

lcdout $FE,1, "DutyCycle: ", dec DutyCycle
lcdout $FE,$C0, "Frequency: ", dec Frequency
pause 100

HPWM 1,DutyCycle,Frequency 'channel, dutycycle, frequency
pause 20

goto Mainloop

END

Archangel
- 9th May 2013, 09:37
Solder-less breadboards have a ton of capacitance, between traces, probably need some on the crystal to get reliable OSC start . . . also add caps to LCD power pins. If you're using a resonator use HS not XT in your configs?

lerameur
- 9th May 2013, 10:41
I have a 1uF cap, and using 4mhz internal clocking.

Acetronics2
- 9th May 2013, 20:31
may preset the outputs levels ...

and explicitly write the chip config ...

lerameur
- 9th May 2013, 21:06
I have an earlier version of that program, ( and no I changed it since) and that version work, meaning does not have this problem.
I guess something is wrong with the code..

K

Acetronics2
- 10th May 2013, 07:42
Ok, Ken ...

as you always know where the problem is ... I wish you a nice day !

Alain

lerameur
- 10th May 2013, 15:26
''as you always know where the problem is ...'' where is that coming from ?!!

K

Demon
- 10th May 2013, 18:52
I can only assume he is referring to your comment that the problem must be in the code.

Robert

lerameur
- 10th May 2013, 19:53
yep, thats why I posted the code. I might of changed something in the code that made it slow, because My older chip (which i dont have the code now) dont have a slow start. only this one. Maybe its the chip itself. i cannot use another chip, I dont have one and I dont want to erase the working one.. i'll keep it as my reference.

K

AvionicsMaster1
- 10th May 2013, 23:56
What chip are you using? Could you add a schematic also please?

wdmagic
- 11th May 2013, 05:19
I had a issue with time using a 16F877 chip the first time, I tried setting it to internal OSC in the fuse section of my programmer software, Apparently i did something wrong because it took about 1 minute for my lcd to come on, and even though my longest pause was 1 second, the fastest updates on my lcd were about 30 seconds, talk about problems with adc and such, I gave up on it at the time and havent used a 877 since. Im sure its something simple, if your using a external crystal make sure its got good connections to board, if its shorted or open perhaps the chip is changing to internal osc to prevent damage? not sure logically as long as your board is wired identical to the breadboard connections there is no logical reason it should not fuction the same... with the exception of capacitance, resistance, and inductance inherant in using jumper wires and mechanical connections. this is not usually a problem on breadboards. likely your problem would be in reverse, it works on PCB but not on breadboard if that was the issue.
Perhaps, based on what you have other than your PIC, perhaps leave the PIC off the PCB and check continuity on buttons, diodes, etc.

and dont forget to take a break or work on some other PIC project for a bit. Sometimes I get into bulldozer mode when I have a problem, 12 hours later im fruserated and tired and its still not working... but a break or playing with some other code makes me relax a bit and sometimes the fix just comes when your not trying so hard.

when I design PCB's it helps sometimes to print it out and the schematic and compare and mark off parts and connections, see if your missing something or have something in the wrong location.

Hope you figure it out.

Archangel
- 14th May 2013, 06:37
Hi Ken,
Let's have a look at your config statements please . . . Are you using internal osc on the breadboard too?
Sometimes if PICs power up too slowly they flounder a bit before starting, also backfeeds make for strange behavior. . .

AvionicsMaster1
- 14th May 2013, 13:50
According to the PBP3 manual LCDOUT command: "A program should wait for up to half a second before sending the first command to
an LCD. It can take quite a while for an LCD to start up". I don't see the wait time in your code.

Is it possible to have full code, schematic and some part numbers of major components?

Demon
- 14th May 2013, 14:03
...I don't see the wait time in your code.

Is it possible to have full code, schematic and some part numbers of major components?


Pause 1500 after defines.

Maybe it should be moved after all registers are set?

Robert

AvionicsMaster1
- 14th May 2013, 14:36
I thought that pause should be in your main loop. You'd do all the stuff and get the data ready for transmit, pause 500 and then send it to the LCD. I assumed that time was needed to get the LCD to warm up once your main loop starts not simply after the chip is powered up.

I'd like to know chip as I'm wondering if OSCCON statement is correct.

Acetronics2
- 14th May 2013, 20:28
Hi, the Holy Squad ... ;)

I found this was overall a bit strange ...

so, rewrote the program and tested it with ISIS ... ( note it works fine NOW ... with ISIS !!! )

just change the DEC3 and DEC4 ( lcdout section ) into DEC ...

and, please, tell me your results ... :confused:

There's something I really do not understand here ...Alain




'************************************************* ***************
'* Name : UNTITLED.BAS *
'* Author : [select VIEW...EDITOR OPTIONS] *
'* Notice : Copyright (c) 2013 [select VIEW...EDITOR OPTIONS] *
'* : All Rights Reserved *
'* Date : 10/05/2013 *
'* Version : 1.0 *
'* Notes : *
'* : *
'************************************************* ***************
INCLUDE "modedefs.bas" 'Includes supoprt for PicBasic language

OSCCON = %01101000 ' 16F 88 4 Mhz ... for those who didn't find it ... ( LOL )
DEFINE OSC 4


DEFINE LCD_DREG PORTB ' Set LCD Data port
DEFINE LCD_DBIT 4 ' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_RSREG PORTA ' Set LCD Register Select port
DEFINE LCD_RSBIT 2 ' Set LCD Register Select bit
DEFINE LCD_EREG PORTA ' Set LCD Enable port
DEFINE LCD_EBIT 3 ' Set LCD Enable bit
DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
DEFINE LCD_LINES 2 ' Set number of lines on LCD
DEFINE LCD_COMMANDUS 2500
DEFINE LCD_DATAUS 250
DEFINE CHAR_PACING 2000
pause 1500
LCDOUT $FE,1


' Define ADCIN parameters
Define ADC_BITS 10 ' Set number of bits in result
Define ADC_CLOCK 3 ' Set clock source (3=rc)
Define ADC_SAMPLEUS 50 ' Set sampling time in uS

DEFINE CCP1_REG PORTB
DEFINE CCP1_BIT 0

CMCON = 7
CVRCON = 0

ANSEL = %00000011 ' set AN0, AN1 as analog, others to digital
ADCON0 = %11000001 ' Configure and turn on A/D Module
ADCON1 = %10000000' Set PORTA analog for ten bit ADC

PORTA = 0
PORTB = 0
TRISB = %01000010
TRISA = %00000111

DutyCycle var word
OldDutyCycle Var Word
Frequency var word
OldFrequency VAR word

WHILE 1

'ADCON0.2 = 1 'Start Conversion
pause 20
ADCIN 0, DutyCycle 'Read channel PORTA.0 Duty Cycle
ADCIN 1, Frequency 'Read channel PORTA.1 Frequency

'Frequency = Frequency + 245
'DutyCycle = DutyCycle/4

IF Frequency <> OldFrequency OR DutyCycle <> OldDutyCycle THEN

lcdout $FE,2, "DutyCyc: ", dec3 DutyCycle/4
lcdout $FE,$C0, "Frequen: ", dec4 Frequency+245
pause 100

HPWM 1,DutyCycle/4,Frequency+245 'channel, dutycycle, frequency
OldFrequency = Frequency
OldDutyCycle = DutyCycle
pause 20
ENDIF

WEND

END

Acetronics2
- 14th May 2013, 20:51
Hi,

Nothing Strange .... Just Shame on me :D

Alain

PS: F....ing Timeout !!! I begin to think just a Lester's trick to get more posts on the forum counter ... :rolleyes:

lerameur
- 16th May 2013, 01:54
Thanks for he program Alain, way better then mine
I changed breadboard, redone the circuit and it works !! go figure....
I tried opersting at 1Mhz to get slower output frequency. used
OSCCON = %01001000 '
but DEFINE OSC 1 do not work.
Do I have to do something else ?
K

Acetronics2
- 16th May 2013, 06:27
Yes ...

Urgent to learn your Holy Manual !!!

Alain

lerameur
- 16th May 2013, 13:46
Hey
belive me I had a look..
page 278 and 279 of the manual states the define and OSCCON values.
The datasheet talks about the OSCCON value which I set. But the define OSC 1 Mhz do not work. Lowest it will go is 4Mhz.
Datasheet stipulates internal oscillation can go as low as 31khz...

AvionicsMaster1
- 16th May 2013, 14:38
I'd like to see the rest of your code but is OSCCON = %01001000 correct? Shouldn't it be OSCCON = %01001110? I'm assuming you're using an internal oscillator, should be stable and it should be used as system clock. I don't know why 4Mhz worked but, if that's all you changed between compiles, then try that.

This is for a 16F88 and is on page 40 of the datasheet.

lerameur
- 16th May 2013, 14:51
ya that works, that bit at position 1. Ithink that did it. thanks

mackrackit
- 16th May 2013, 14:55
Bits 0 through 3 of OSCCON are read only?

lerameur
- 16th May 2013, 15:24
Actually it compiles , but after careful testing, the frequency is all over the place when using only OSCCON = %01001110..

peterdeco1
- 16th May 2013, 19:10
Hi All. After reading this thread, it made me look at something I now don't understand. I've been using this table for years for 'F819 and 'F88. But when you convert the decimal numbers to binary, the bits don't match the table in the datasheet. When you pick the bits and convert to decimal, they don't match the table. Does anyone know why? Thank you.


'osccon values for 16f818/819:
'OSCCON = $00 'for 31.25 khz
'OSCCON = $10 '125khz
'OSCCON = $20 '250khz
'OSCCON = $30 '500khz
'OSCCON = $40 '1mhz
'OSCCON = $50 '2mhz
OSCCON = $60 '4mhz 'set int osc to 4mhz
'OSCCON = $70 '8mhz

Demon
- 16th May 2013, 21:29
You can change READ-ONLY registers all you want. The PIC will just ignore your requests at best.

Robert

peterdeco1
- 17th May 2013, 11:11
As you can see, the 4MHZ is uncommented. If you convert the number to binary, it doesn't match the osccon bits in the datasheet when you select 4MHZ. Same with the reverse, select the 4MHZ bits in the datasheet, convert to decimal and it doesn't match the table. Yet, the numbers in the table do work.

'osccon values for 16f818/819:
'OSCCON = $00 'for 31.25 khz
'OSCCON = $10 '125khz
'OSCCON = $20 '250khz
'OSCCON = $30 '500khz
'OSCCON = $40 '1mhz
'OSCCON = $50 '2mhz
OSCCON = $60 '4mhz 'set int osc to 4mhz
'OSCCON = $70 '8mhz

Dave
- 17th May 2013, 12:23
These hex values match the 16F818 as expected.

from your code..........................
'osccon values for 16f818/819:
'OSCCON = $00 'for 31.25 khz
'OSCCON = $10 '125khz
'OSCCON = $20 '250khz
'OSCCON = $30 '500khz
'OSCCON = $40 '1mhz
'OSCCON = $50 '2mhz
OSCCON = $60 '4mhz 'set int osc to 4mhz
'OSCCON = $70 '8mhz

from the data sheet.....................
bit 6-4 IRCF2:IRCF0: Internal Oscillator Frequency Select bits
111 = 8 MHz (8 MHz source drives clock directly)
110 = 4 MHz
101 = 2 MHz
100 = 1 MHz
011 = 500 kHz
010 = 250 kHz
001 = 125 kHz
000 = 31.25 kHz (INTRC source drives clock directly)

I don't understand the issue?

Demon
- 17th May 2013, 13:56
Never mind

lerameur
- 17th May 2013, 20:10
so I guess
the clocking below 4Mhz cannot be used with HPWM ?

Cause I need to get down to 50Hz, my choices is left with pulsout command.
I'll see if I CAN use it on the same pin.
K

AvionicsMaster1
- 18th May 2013, 03:05
Bits 0 through 3 of OSCCON are read only? I'm curious what do you mean? Bits 0 to 3 set status bit, oscillator stability and mode select. Can't these be set at beginning of code?

peterdeco1
- 19th May 2013, 11:29
Sorry Dave. I still don't get it. 60 on the table I use comes out to 0111100 in binary. Are we choosing the bits from left to right (MSB first) instead of right to left (LSB first)?

Sherbrook
- 19th May 2013, 12:30
I think this is the problem
You are reading $60 as decimal when it is a HEX number
60 = 00111100 in binary
$60 = 01100000 in binary

Phil

peterdeco1
- 20th May 2013, 11:26
Thank you Phil. Makes perfect sense now.