Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Help with programming a pic to oscillate

Status
Not open for further replies.

piper91765

New Member
555 timer

How accurate does your pulse need to be? You can get a reasonably accurate 1Hz pulse by using a 555 timer. The best part is that it is simple (no programming required), has few parts, and you could build it for pennies. Check out this link:



You can calculate the pulses using the formulas provided in the document.

t1= 0.693(R1+R2)C
t2= 0.693(R2)(C)

If your pulse is 1Hz, that means one cycle per second; therefore t1=t2= 0.5 seconds

Then just plug in the numbers and solve. Pick a value for R1 and solve simultaniously for R2 and C.

0.5=.693(R1+R2)C
0.5=.693(R2)(C)

Hope that helps.

Btw, for greater accuracy, use a trimmer for R2 and fine tune the circuit until it is exactly 1 Hz
 
Last edited:

alifred

Member
Hi mike,

I am breadboarding, so I programed my PIC and then set it up with the crystal. I tried using 22pF caps, because that was all I had got, and it didn't work.

Would this make sense??

Are the caps just too low??

Cheers,

Fred
 

Pommie

Well-Known Member
Most Helpful Member
Hi Fred,

The caps may be too low or it may be something else, can you put 2 caps in parallel on each leg of the crystal? Did you change the config to LP from XT? What are you using to program your chip? Are you sure it is being programmed?

Mike.
 

alifred

Member
Hi Mike,

I could put 2 caps on each leg of the crystal if i had them! I will have to get some new caps! I converted the assembler file to hex using MPASMWIN and then programmed the PIC with Progpic2.
When i had programmed the PIC, i saved a file of the readback data (see below!)

Code:
:1000000083160313061083120313013090000F1E92
:1000100006100F1A06140728FF3FFF3FFF3FFF3F60
:10002000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3FE0
:10003000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3FD0
:10004000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3FC0
:10005000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3FB0
:10006000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3FA0
:10007000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3F90
:10008000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3F80
:10009000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3F70
:1000A000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3F60
:1000B000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3F50
:1000C000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3F40
:1000D000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3F30
:1000E000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3F20
:1000F000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3F10
:10010000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3FFF
:10011000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3FEF
:10012000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3FDF
:10013000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3FCF
:10014000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3FBF
:10015000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3FAF
:10016000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3F9F
:10017000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3F8F
:10018000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3F7F
:10019000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3F6F
:1001A000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3F5F
:1001B000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3F4F
:1001C000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3F3F
:1001D000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3F2F
:1001E000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3F1F
:1001F000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3F0F
:10020000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3FFE
:10021000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3FEE
:10022000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3FDE
:10023000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3FCE
:10024000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3FBE
:10025000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3FAE
:10026000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3F9E
:10027000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3F8E
:10028000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3F7E
:10029000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3F6E
:1002A000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3F5E
:1002B000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3F4E
:1002C000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3F3E
:1002D000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3F2E
:1002E000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3F1E
:1002F000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3F0E
:10030000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3FFD
:10031000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3FED
:10032000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3FDD
:10033000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3FCD
:10034000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3FBD
:10035000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3FAD
:10036000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3F9D
:10037000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3F8D
:10038000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3F7D
:10039000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3F6D
:1003A000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3F5D
:1003B000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3F4D
:1003C000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3F3D
:1003D000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3F2D
:1003E000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3F1D
:1003F000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3F0D
:10040000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3FFC
:10041000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3FEC
:10042000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3FDC
:10043000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3FCC
:10044000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3FBC
:10045000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3FAC
:10046000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3F9C
:10047000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3F8C
:10048000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3F7C
:10049000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3F6C
:1004A000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3F5C
:1004B000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3F4C
:1004C000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3F3C
:1004D000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3F2C
:1004E000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3F1C
:1004F000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3F0C
:10050000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3FFB
:10051000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3FEB
:10052000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3FDB
:10053000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3FCB
:10054000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3FBB
:10055000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3FAB
:10056000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3F9B
:10057000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3F8B
:10058000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3F7B
:10059000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3F6B
:1005A000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3F5B
:1005B000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3F4B
:1005C000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3F3B
:1005D000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3F2B
:1005E000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3F1B
:1005F000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3F0B
:10060000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3FFA
:10061000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3FEA
:10062000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3FDA
:10063000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3FCA
:10064000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3FBA
:10065000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3FAA
:10066000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3F9A
:10067000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3F8A
:10068000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3F7A
:10069000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3F6A
:1006A000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3F5A
:1006B000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3F4A
:1006C000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3F3A
:1006D000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3F2A
:1006E000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3F1A
:1006F000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3F0A
:10070000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3FF9
:10071000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3FE9
:10072000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3FD9
:10073000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3FC9
:10074000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3FB9
:10075000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3FA9
:10076000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3F99
:10077000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3F89
:10078000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3F79
:10079000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3F69
:1007A000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3F59
:1007B000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3F49
:1007C000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3F39
:1007D000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3F29
:1007E000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3F19
:1007F000FF3FFF3FFF3FFF3FFF3FFF3FFF3FFF3F09
:084000000F000F000F000F007C
:02400E00603F11
:10420000FF00FF00FF00FF00FF00FF00FF00FF00B6
:10421000FF00FF00FF00FF00FF00FF00FF00FF00A6
:10422000FF00FF00FF00FF00FF00FF00FF00FF0096
:10423000FF00FF00FF00FF00FF00FF00FF00FF0086
:10424000FF00FF00FF008C008C008C008C008C00B5
:104250008C008C008C008C008C008C008C008C00FE
:104260008C008C008C008C008C008C008C008C00EE
:104270008C008C008C008C008C008C008C008C00DE
:104280008C008C008C008C008C008C008C008C00CE
:104290008C008C008C008C008C008C008C008C00BE
:1042A0008C008C008C008C008C008C008C008C00AE
:1042B0008C008C008C008C008C008C008C008C009E
:1042C0008C008C008C008C008C008C008C008C008E
:1042D0008C008C008C008C008C008C008C008C007E
:1042E0008C008C008C008C008C008C008C008C006E
:1042F0008C008C008C008C008C008C008C008C005E
:00000001FF

There doesn't seem to be the actal code in it which is:

Code:
:020000040000FA
:1000000083160313061083120313013090000F1E92
:0800100006100F1A0614072860
:02400E00603F11
:00000001FF

I did change the LP to XT though!

Thanks


Fred

BTW, can you readback the data off of your PIC that you programmed and got to work, it would be intersting to see the comparason!
 
Last edited:

Nigel Goodwin

Super Moderator
Most Helpful Member
Well this is your actual code, as disassembled from the HEX:

Original

Code:
; Generated by WinPicProg 1.95e, (c) Nigel Goodwin Apr 2005.

            LIST      P=16F627, F=INHX8M
            include "P16F627.inc"
            __CONFIG 0x3D60

; Variable definitions

            ORG     0x0000

            BSF     STATUS    , RP0
            BCF     STATUS    , RP1
            BCF     TRISB     , 00
            BCF     STATUS    , RP0
            BCF     STATUS    , RP1
            MOVLW   0x01
            MOVWF   T1CON
Label_0001  BTFSS   TMR1H     , 04
            BCF     PORTB     , 00
            BTFSC   TMR1H     , 04
            BSF     PORTB     , 00
            GOTO    Label_0001
 
 

            END

Read from the chip

; Generated by WinPicProg 1.95e, (c) Nigel Goodwin Apr 2005.

LIST P=16F627, F=INHX8M
include "P16F627.inc"
__CONFIG 0x3D60

; Variable definitions

ORG 0x0000

BSF STATUS , RP0
BCF STATUS , RP1
BCF TRISB , 00
BCF STATUS , RP0
BCF STATUS , RP1
MOVLW 0x01
MOVWF T1CON
Label_0001 BTFSS TMR1H , 04
BCF PORTB , 00
BTFSC TMR1H , 04
BSF PORTB , 00
GOTO Label_0001

ORG 0x2000
DATA 0x0F
DATA 0x00
DATA 0x0F
DATA 0x00



ORG 0x2123
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C
DATA 0x8C

END

The actual running part of the program is identical, but you have some strange rubbish higher up in data eeprom etc. none of which will affect the programs running.
 

alifred

Member
Hi Mike,

You said when you were breadboarding, you got it to work.

i have 3 questions for you:

1 - how did you tell if it was oscillating? (did you attach an led?)

2 - could you submit a picture of the configuration you used on your breadboard? it would be nice to see how you did it

3 - did you use a watch crystal? if so, where from?

don't worry if u cannot answer all of them!!!

Cheers

Fred
 

alifred

Member
Hi eng1,

The picture attached is a circuit diagram for how to connect the crystal to the PIC. Then all you need to do is to connect the power lines to the PIC and a cable out of RB0 for the pulse.

Fred
 

Attachments

  • clip_image002.gif
    clip_image002.gif
    124 KB · Views: 96

eng1

New Member
The picture attached is a circuit diagram for how to connect the crystal to the PIC. Then all you need to do is to connect the power lines to the PIC and a cable out of RB0 for the pulse.

Fred

With MCLR enabled in the configuration fuses, you need to connect pin 4 to Vdd with a resistor, 1 kohms should be ok. Or disable the external MCLR funtion by changing the config settings: _MCLR_OFF
 
Last edited:

alifred

Member
Hi,

When i try to connect the pulse to my 4510 BCD counter, then it does not count!!!
The spec sheet for the 4510 says that the minimum pulse width for the pulse at 5V is 150ns. It has no max. Shouldn't this mean that it will register the pulse?

Could you program the pic to make the pulse shorter?

Thanks

Fred

(see atachment for PDF manual for the 4510)
 

Attachments

  • mXsqrws.pdf
    141.5 KB · Views: 186

Pommie

Well-Known Member
Most Helpful Member
A pic should be able to clock a cmos counter without any problem. Have you got all the other pins on the 4510 connected correctly. That is, carry in, Preset and reset grounded and U/D tied high.

It would be fairly easy to change the duty cycle of the pulses but it shouldn't be necessary.

Mike.
Edit, if you want to try a shorter pulse then change the code to,
Code:
main	movfw	TMR1H		;get timer high byte
	andlw	b'00011111'	;keep the lower 5 bits
	btfss	STATUS,Z	;if not zero (97% of the time)
	bcf	PORTB,0		;clear portB bit 0
	btfsc	STATUS,Z	;if zero (3% of the time)
	bsf	PORTB,0		;set bit 0 of port b
	goto	main		;do it all again
This will give a 30mS pulse. To make it double change the b'00011111' to b'00011110'. Making more bits zero (from the right) will double the time for each additional zero.
 
Last edited:

alifred

Member
hi,
I think my problem with the counter is that I have not got big enough capacitors around the crystal. I only have two 22pF ones. It says that I should use 68 or 100pF ones.

Do you think that this is my problem??


Cheers

Fred
 
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top