Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

PIC16F819 8MHz Internal OSC at 5V.

Status
Not open for further replies.

d@nny

Full Member level 5
Joined
May 28, 2011
Messages
246
Helped
11
Reputation
22
Reaction score
11
Trophy points
1,298
Activity points
3,238
DSCF0018.JPG

Code:
processor PIC16F819
#include <p16f819.inc>
__CONFIG _CP_OFF & _WRT_ENABLE_OFF & _CPD_OFF & _CCP1_RB2 & _LVP_OFF & _BODEN_ON & _MCLR_OFF & _WDT_OFF & _PWRTE_ON & _INTRC_IO
J equ 20h
K equ 21h
org 0
goto main
main:
banksel OSCCON
movlw B'01110000'
movwf OSCCON
banksel TRISB
movlw B'00000000'
movwf TRISB
banksel PORTB
Flasher:
bcf PORTB , 1
bsf PORTB , 0
bcf PORTB , 0
bsf PORTB , 1
goto Flasher
fin:
goto fin
delay:
movlw D'20'
movwf K
clrf J
delay1:
nop
decfsz J , f
goto delay1
delay2:
nop
decfsz J , f
goto delay2
decfsz K , f
goto delay1
return
end
 

wp100

Advanced Member level 5
Joined
May 15, 2009
Messages
3,056
Helped
883
Reputation
1,781
Reaction score
736
Trophy points
113
Location
Prime Meridian
Activity points
0
Hi,

What pin /signal are you measuring as 1meg ?

Don't forget the 8meg Osc is divided by 4 to produce 1 machine Cycle.
Not clearly mentioned in the Osc section of the datasheet - but is detailed on the first page of the Instruction Set in the datasheet

What is the length of your delay routine , have you checked its timing with Mplabs Sim Stopwatch ? - do you know how to ??


Edit - as you can see from the Instruction Set the BSF takes 1 Cycle.....
 

d@nny

Full Member level 5
Joined
May 28, 2011
Messages
246
Helped
11
Reputation
22
Reaction score
11
Trophy points
1,298
Activity points
3,238
i am measuring RBO and RB1
 

wp100

Advanced Member level 5
Joined
May 15, 2009
Messages
3,056
Helped
883
Reputation
1,781
Reaction score
736
Trophy points
113
Location
Prime Meridian
Activity points
0
Hi,


Ok, can you now see how that is the correct frequency ..?
 

d@nny

Full Member level 5
Joined
May 28, 2011
Messages
246
Helped
11
Reputation
22
Reaction score
11
Trophy points
1,298
Activity points
3,238
consider one thing more that the temperature of the room was more than 35 celsius or 95 degree Fahrenheit. the frequency on counter was daviation from 1.0039 to 1.0041 MHz :p
 

wp100

Advanced Member level 5
Joined
May 15, 2009
Messages
3,056
Helped
883
Reputation
1,781
Reaction score
736
Trophy points
113
Location
Prime Meridian
Activity points
0
Hi,

Drat, did not take ambient temperature into account :lol:

While the internal osc is good for many programs for very critical timings you may need to use a xtal.

As you can see your internal osc is running at 8 meg / 4 to give a 2meg clock speed / or Cycle time of 0.5us.

Here is a digital scope of your outputs RB0 and RB1.

Notice how the upper trace, RBO is high for 1 div of the scope = 0.5s which confrims its running at the correct speed.
If you follow the traces though with your code and the cycle times for each instruction you will see its all correct.
Using 1 cycle per instruction will not give the correct result, if you check the Instruction sheet you will see that a few of them like the GOTO take 2 cycles.


happy coding ...
 

Attachments

  • ScreenShot001.jpg
    ScreenShot001.jpg
    69.2 KB · Views: 5

d@nny

Full Member level 5
Joined
May 28, 2011
Messages
246
Helped
11
Reputation
22
Reaction score
11
Trophy points
1,298
Activity points
3,238
Now is it ok


#include <p16f819.inc>
__CONFIG _CP_OFF & _WRT_ENABLE_OFF & _CPD_OFF & _CCP1_RB2 & _LVP_OFF & _BODEN_ON & _MCLR_OFF & _WDT_OFF & _PWRTE_ON & _INTRC_IO
J equ 20h
K equ 21h
org 0
goto main
main:
banksel OSCCON
movlw B'01110000'
movwf OSCCON
banksel TRISB
movlw B'00000000'
movwf TRISB
banksel PORTB
Flasher:
bcf PORTB , 1
bsf PORTB , 0
nop
nop
bcf PORTB , 0
bsf PORTB , 1
goto Flasher
fin:
goto fin
delay:
movlw D'20'
movwf K
clrf J
delay1:
nop
decfsz J , f
goto delay1
delay2:
nop
decfsz J , f
goto delay2
decfsz K , f
goto delay1
return
end
 

wp100

Advanced Member level 5
Joined
May 15, 2009
Messages
3,056
Helped
883
Reputation
1,781
Reaction score
736
Trophy points
113
Location
Prime Meridian
Activity points
0
Now is it ok

??

Not sure what frequency you are trying to get ?
As you can see your waveform is not a square wave.
If you are trying to achive a true 1meg square wave you cannot achive it at this clock speed, let alone do any other processing.

Flasher: ; CYCLES
bcf PORTB , 1 ; 1 _____---_____
bsf PORTB , 0 ; 1 _---_____---_
nop ; 1
nop ; 1
bcf PORTB , 0 ; 1
bsf PORTB , 1 ; 1
goto Flasher ; 2 total 8cycles = 4us or 250khz
fin:
 

Attachments

  • ScreenShot002.jpg
    ScreenShot002.jpg
    70.2 KB · Views: 4

d@nny

Full Member level 5
Joined
May 28, 2011
Messages
246
Helped
11
Reputation
22
Reaction score
11
Trophy points
1,298
Activity points
3,238
Please check this code. I have made a osc for dc to ac inverter. When i put it in inverter this happens.

DSCF0010.JPG

processor PIC16F819
#include <p16f819.inc>
__CONFIG _CP_OFF & _WRT_ENABLE_OFF & _CPD_OFF & _CCP1_RB2 & _LVP_OFF & _BODEN_ON & _MCLR_OFF & _WDT_OFF & _PWRTE_ON & _INTRC_IO
J equ 20h
K equ 21h
org 0
goto main
main:
banksel OSCCON
movlw B'01110000'
movwf OSCCON
banksel TRISB
movlw B'00000000'
movwf TRISB
banksel PORTB
Flasher:
bcf PORTB , 1
bsf PORTB , 0
nop
nop
call delay
bcf PORTB , 0
bsf PORTB , 1
call delay
goto Flasher
fin:
goto fin
delay:
movlw D'10'
movwf K
clrf J
delay1:
nop
decfsz J , f
goto delay1
delay2:
nop
decfsz J , f
goto delay2
decfsz K , f
goto delay1
return
end



i have insert my 50Hz pic16f819 in inverter for dc12v to 220vac. Amazing. The 50hz increased to 200 hertz and when i tried to check output with analouge metre it burns and the second shous at 250 to 30 volts with very trimbling pin. Why frequency increased to 200 hertz?
Transistors are TIP741 4 transistors 2 each side.
below the pic what i have actually done. consider each transistor 2 as i have combined their all three pins together.


TIP741.JPG
 

d@nny

Full Member level 5
Joined
May 28, 2011
Messages
246
Helped
11
Reputation
22
Reaction score
11
Trophy points
1,298
Activity points
3,238
ya i have burnt my two analogue volt meter when check output 220 volts. the meter were set at 1000 volt. and he frequency counter increased to 203 hertz from 49 hertz.
 

wp100

Advanced Member level 5
Joined
May 15, 2009
Messages
3,056
Helped
883
Reputation
1,781
Reaction score
736
Trophy points
113
Location
Prime Meridian
Activity points
0
Hi,

Your program produces a decent enough opposed 50hz signal.

No experience of inverters, but would think the change in frequency might be due to the power supply to the pic being disrupted when the transistors /coil take too much power.

The 1000uf after the 7805 should be on the input side, use 100uf on the output side plus a 100nf directly across the pics pos and neg pins.

Also fit a diode in series in the line between the battery and the 1000uf cap so that the output stages cannot drain power away from the pic.


There are loads of Inverter questions in this forum , worth a good look as I doubt such a simple circuit will provide you with a practical output.
You only have to look at ready made inverters to see how complex they are and for the price most seem fair value.
 

Attachments

  • ScreenShot001.jpg
    ScreenShot001.jpg
    67.7 KB · Views: 3

d@nny

Full Member level 5
Joined
May 28, 2011
Messages
246
Helped
11
Reputation
22
Reaction score
11
Trophy points
1,298
Activity points
3,238
Inverter with modified sinewave . I have used to following code to make this :p

processor PIC16F819
#include <p16f819.inc>
__CONFIG _CP_OFF & _WRT_ENABLE_OFF & _CPD_OFF & _CCP1_RB2 & _LVP_OFF & _BODEN_ON & _MCLR_OFF & _WDT_OFF & _PWRTE_ON & _INTRC_IO
J equ 20h
K equ 21h
org 0
goto main
main:
banksel OSCCON
movlw B'01110000'
movwf OSCCON
banksel TRISB
movlw B'00000000'
movwf TRISB
banksel PORTB
Flasher:
bcf PORTB , 1
call delay10ms
bsf PORTB , 0
call delay8ms
nop
nop
bcf PORTB , 0
call delay10ms
bsf PORTB , 1
call delay8ms
goto Flasher
fin:
goto fin
delay2ms:
movlw D'2'
movwf K
clrf J
delay1:
nop
decfsz J , f
goto delay1
delay2:
nop
decfsz J , f
goto delay2
decfsz K , f
goto delay1
return
delay8ms:
movlw D'8'
movwf K
clrf J
delay11:
nop
decfsz J , f
goto delay11
delay22:
nop
decfsz J , f
goto delay22
decfsz K , f
goto delay1
return
end

 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top