Post the code your really using there no way to help you without it.
Swordfish doesn't like osccon setting in the main code I've had the osc not start up to full speed hours after the chip is powered on.
LG said:people tend to stick with one chip or another! no idea why as i like to use them all
Device = 18F13K22
Clock = 8
Include "osc1322.bas"
// alias to port pin...
Dim LED1 As PORTB.5
Dim led2 As PORTB.6
Dim Led3 As PORTC.2
// main program...
Output(LED1) ' portb.6 pin 11 BLUE
Output(led2) ' portb.5 pin 12 RED
Output(Led3) ' not connected yet port c.2 pin 14 GREEN
High(LED1)
High (led2)
High (Led3)
While 1 = 1
Low (led2)
DelayMS (1000)
High (led2)
DelayMS(1000)
Wend
Here is the module NOTE only the last 5 lines are enabled.
[CODE]Module osc1322
{
Config FOSC = HS 'HS oscillator
Config PLLEN = OFF ' PLL is under software control
PCLKEN = On ' Primary clock enabled
FCMEN = OFF ' Fail-Safe Clock Monitor disabled
IESO = OFF 'Oscillator Switchover mode disabled
PWRTEN = OFF ' PWRT disabled
BOREN = OFF ' Brown-out Reset disabled in hardware and software
BORV = 22 ' VBOR set to 2.2 V nominal
WDTEN = OFF ' WDT is controlled by SWDTEN bit of the WDTCON register
WDTPS = 128 ' 1:128
MCLRE = OFF ' RE3 input pin enabled; MCLR disabled
HFOFST = OFF ' The system clock is held off until the HFINTOSC is stable.
STVREN = On 'Stack full/underflow will cause Reset
LVP = OFF ' Single-Supply ICSP disabled
BBSIZ = OFF ' 1KW boot block size
XINST = OFF ' Instruction set extension and Indexed Addressing mode disabled
}
mclr = 0
OSCCON = %01100011 ' SCS<1:0> 00 = Primary clock
OSCCON2 = %00000111 ' PRI_SD<2> = Osc drive circuit on
ANSEL = %00000000 ' all digital
ANSELH = %00000000 ' all digital
'TRISC = %00000000 ' portC cleared for output
Device = 18F2420
Clock = 8
'Include "osc1322.bas"
include "internaloscillator.bas"
// alias to port pin...
Dim LED1 As PORTB.5
Dim led2 As PORTB.6
Dim Led3 As PORTC.2
// main program...
Output(LED1) ' portb.6 pin 11 BLUE
Output(led2) ' portb.5 pin 12 RED
Output(Led3) ' not connected yet port c.2 pin 14 GREEN
High(LED1)
High (led2)
High (Led3)
While 1 = 1
Low (led1)
DelayMS (1000)
High (led1)
DelayMS(1000)
Low (led2)
DelayMS (1000)
High (led2)
DelayMS(1000)
Wend
Sigh. MrDEB, I truly wish you could post a message with pertinent details that can be comprehended by mere mortals such as myself.
In the paragraph above, you talk about PICkit calibration, internal oscillator settings and etc and say "it doesn't work." From that statement, nobody can know what "it" is.
Questions. A clear, concise answer is required to each before I will do anything further to help you.
1. Did you run the Vdd calibration procedure under the PICkit 2 GUI?
2. When you attempt to write to the 18F13k22 chip, does it complete satisfactorily or is there an error message displayed? If so, post screen captures of the PICkit 2 GUI and of the error message.
3. Did you verify the code was written correctly to the 18F13K22? It's an option under the PICkit 2 GUI.
4. If and only if the code was written into the 18F13K22, how do you know it's not working? Simplest possible program. Post code and schematic diagrams in a clear readable format. I'm not going to guess at what you're doing or assume you have correct connections. Sorry, past performance suggests to do so is foolish.
5. If the internal oscillator code isn't working (post your actual code), and the chip is actually being programmed (verified in the PICkit 2 GUI), try it with a crystal and 22 pF caps.
Sorry to be blunt, but if you want help, you need to post all of the details clearly and concisely with appropriate documentation posted. Many of us have been burned in the past by making assumptions about what you are asking, or assuming schematics actually show what you have connected.
I do not believe the 18F13K22 chip should be any more difficult than any other 18F chip to use, but as always, attention to detail and the data sheet will be required.
Then that's a problem. You HAVE to set the CONFIG properly, and as been said many times you can't rely on the defaultsHere is the module NOTE only the last 5 lines are enabled.
Module osc1322
Config
FOSC = IRC, ' internal RC osc
PLLEN = OFF, ' PLL is under software control
PCLKEN = OFF, ' Primary clock drive disabled (using internal)
FCMEN = OFF, ' Fail-Safe Clock Monitor disabled
IESO = OFF, ' Oscillator Switchover mode disabled
PWRTEN = ON, ' PWRT enabled
BOREN = OFF, ' Brown-out Reset disabled in hardware and software
BORV = 22, ' VBOR set to 2.2 V nominal
WDTEN = OFF, ' WDT is controlled by SWDTEN bit of the WDTCON register
WDTPS = 128, ' 1:128
MCLRE = ON, ' RA3 input pin disabled; MCLR enabled
HFOFST = OFF, ' The system clock is held off until the HFINTOSC is stable.
STVREN = ON, 'Stack full/underflow will cause Reset
LVP = OFF, ' Single-Supply ICSP disabled
BBSIZ = OFF, ' 1KW boot block size
XINST = OFF, ' Instruction set extension and Indexed Addressing mode disabled
DEBUG = OFF
OSCCON = %01100010 // IRCF=8MHz, SCS1=1 (int osc)
OSCCON2 = 0
OSCTUNE = %10000000 // INTSRC=1, PLLEN=0, TUN=0
// set all pins digital
ANSEL = $00
ANSELH = $00
CM1CON0 = 0
CM2CON0 = 0
VREFCON1 = $00
{
*****************************************************************************
* Name : UNTITLED.BAS *
* Author : [select VIEW...EDITOR OPTIONS] *
* Notice : Copyright (c) 2013 [select VIEW...EDITOR OPTIONS] *
* : All Rights Reserved *
* Date : 11/18/2013 *
* Version : 1.0 *
* Notes : Module osc1322 for 18F13K22 *
* : *
*****************************************************************************
}
Device = 18F13K22
Clock = 8
Include "osc1322.bas"
Include "RandGen.bas"
Include "Util1322.bas"
Dim TMR2IE As PIE1.1, // TMR2 interrupt enable
TMR2IF As PIR1.1, // TMR2 overflow flag
TMR2ON As T2CON.2, // Enables TMR2 to begin incrementing
Signal_Pin As PORTB.0 // Signal output to frequency meter
Dim Red_Pin As PORTb.5, //was b.0
Green_Pin As PORTc.5, //was b1
Blue_Pin As PORTb.6, //was b2
Red_Duty As Byte,
Green_Duty As Byte,
Blue_Duty As Byte,
Red_DutyVal As Byte,
Green_DutyVal As Byte,
Blue_DutyVal As Byte,
RandomVal As Byte
Dim led As PORTB.3
Dim uS As Word,
mS As Word,
ranval(1)As Word
Interrupt TMR2_Interrupt()
' High(Signal_Pin)
Save(0) // Back up system variables
If TMR2IF = 1 Then // Check if the interrupt was from TMR2
TMR2IF = 0 // Clear the TMR2 interrupt flag
uS = uS + 50
If uS >= 1000 Then
uS = uS - 1000
Inc(mS)
EndIf
Inc(Red_DutyVal)
Inc(Green_DutyVal)
Inc(Blue_DutyVal)
If Red_DutyVal > Red_Duty Or Red_Duty = 250 Then
Red_Pin = 0
Else
Red_Pin = 1
EndIf
If Green_DutyVal > Green_Duty Or Green_Duty = 0 Then
Green_Pin = 0
Else
Green_Pin = 1
EndIf
If Blue_DutyVal > Blue_Duty Or Blue_Duty = 0 Then
Blue_Pin = 0
Else
Blue_Pin = 1
EndIf
EndIf
{
led = 0
delayms(1000)
led = 1
delayms(1000)
} //
Restore // Restore system variables
' Low(Signal_Pin)
End Interrupt
Private Sub TMR2_Initialize()
TMR2ON = 0 // Disable TMR2
TMR2IE = 0 // Turn off TMR2 interrupts
PR2 = 149 // TMR2 Period register PR2
T2CON = %00000000 // T2CON 0:1 = Prescale
// 00 = Prescale is 1:1
// 01 = Prescale is 1:4
// 1x = Prescale is 1:16
// 3:6 = Postscale
// 0000 = 1:1 postscale
// 0001 = 1:2 postscale
// 0010 = 1:3 postscale...
// 1111 = 1:16 postscale
TMR2 = 0 // Reset TMR2 Value
TMR2IE = 1 // Enable TMR2 interrupts
TMR2ON = 1 // Enable TMR2 to increment
Enable(TMR2_Interrupt)
End Sub
// Start Of Program...
Low(Red_Pin)
Low(Green_Pin)
Low(Blue_Pin)
Red_Duty = 0 ' to decrease the amount of color (led on time) insert up to 255
Green_Duty = 5 ' to increase amount of on time < 255
Blue_Duty =250 ' contemplating adding PWM to change the DutyVal value
Red_DutyVal = 0
Green_DutyVal = 0
Blue_DutyVal =0
led = 1
uS = 0
mS = 0
RandGen.Initialize(255) // Initialize the Random Number generator
TMR2_Initialize // Setup and enable TMR2
While true // Create an infinite loop
RandomVal = RandGen.Rand // Grab a random number from 0 to 255
Enable(TMR2_Interrupt)
Select RandomVal
// Find out what colour to increase/decrease
Case 0 To 42
If Red_Duty =RandomVal-5
Then mS = 0
Repeat
Until mS = 10
And Red_Duty>0
End If
Case 43 To 83
If Red_Duty > 0
Then mS = 0
Repeat
Until mS = 25
Inc(Red_Duty)
EndIf
Case 84 To 127
If Green_Duty =RandomVal-20
Then mS = 0
Repeat
Until mS = 19
Inc(Green_Duty)
End If
Case 128 To 170
If Green_Duty > 0
Then mS = 0
Repeat
Until mS = 10
Inc(Green_Duty)
DelayMS(5000)
EndIf
Case 171 To 212
If Blue_Duty = RandomVal-30
Then mS = 0
Repeat
Until mS = 19
Inc(Blue_Duty)
End If
Case 213 To 255
If Blue_Duty > 0
Then mS = 0
Repeat
Until mS = 20
inc(Blue_Duty)
EndIf
End Select
Wend
End
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?