Continue to Site

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.

Precautions using K series PIC's

Status
Not open for further replies.

MrDEB

Well-Known Member
I am jump starting a privious project fr an LED candle using a tri-color LED. Got to looking at quanity prices and see the K series pic's are cheaper. I need 30+ candles so price is a major consideration.
Looking at the 18F13k22 pic with a Vdd of 5v (3 AA batteries) and planning on controlling a tri color led( 3=180 ohm resistors). but having never ventured into using the K series has me guessing?
Using a Pickit2 to program the pic and have a code that works well on a 18F1320 as well as a 18F2420 but issues with using the K series?? if any.
 
Ive been using the pic18f26k80 and the pic18f46k80 for a while now w/ pickit3. I like them better then the 16's once I learned C.... I got the pickit3 board kit to try them last year and really like them.
 
I am under the impression that a Pickit2 can be used to program the K series as well but correct me if I am wrong before I order a couple of the K series to experiment with before ordering 30+ pics
 
don't know about what chips, you would have to check the "readme" files in the pickit2 help files, or the Microchip sub files in the same. I remember seeing what chips were compatible in those files. I don't have those in this computer as of yet.
 
It certainly looks like you can use the Pickit-2. As long as you are using the standalone GUI and not MPLAB. :)
**broken link removed**
 
Thanks for the Link. I should have mentioned that I am planning on using SWORDFISH and the PICKIT2 which I see from the link that the 18F13K22 is supported. No need to use the MPLAB
 
i have started with the K chips they are great! i had trouble with some using the junebug so thats when i upgraded to the pk3 and now icd3. for rgb candles most simple route code wise i would have thought was the 18f1330 because it has 3 independent pwm outputs, so perfect for easy pwm on 3 channels. i cant remember wich K chips do what now but when i used them it was for the number of ADC channels they have and i want to try out the CTMU.
how many candles per chip you going to do?
 
I am planning on making 25 separate candles and using SWORDFISH as code language. This code works rather well. I was involved in scouting and used this same code for a neckerchief slide with a campfire picture. Looked really nice. Presently looking at $7 per candle but looking at using a different battery holder to lower the cost. Just a pcboard, RGB led, soic pic, 4 resistors, a cap, battery holder, switch and section of pvc pipe for votive candle.
Code:
{
*****************************************************************************
*  Name    : UNTITLED.BAS                                                  *
*  Author  : Doug Bezaire                                                  *
*  Notice  : Copyright (c) 2010 [select VIEW...EDITOR OPTIONS]              *
*          : All Rights Reserved                                            *
*  Date    : 3/26/2010                                                      *
*  Version : 1.0                                                            *
*  Notes  :                                                                *
*          :                                                                *
*****************************************************************************
}
Device = 18F2420
Clock = 8

Include "InternalOscillator.bas"
Include "RandGen.bas"
Include "Utils.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 PORTA.0,        //was b.0
    Green_Pin As PORTA.1,      //was b1
    Blue_Pin As PORTA.2,        //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 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 = 0 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                    //
    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 = %00000001        // 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 = 30
Green_Duty = 10
Blue_Duty = 5
Red_DutyVal = 0
Green_DutyVal = 0
Blue_DutyVal =0
uS = 0
mS = 0

RandGen.Initialize(128)      // 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
    // Select RandomVal        // Find out what colour to increase/decrease
        //Case 0 To 42
            Red_Duty =RandomVal-5
                //mS = 0
            // (Red_Duty)=Rand(1)
              // Repeat
              // Until mS = 19
              // and Red_Duty>0
          // endif
         
           
        //Case 43 To 84
            If Red_Duty > 0
              Then  mS = 0
                Repeat
                Until mS = 19
                Dec(Red_Duty)
            EndIf
      // Case 84 To 127
            Green_Duty =RandomVal-20
              //Then  mS = 0
              //  Repeat
              //  Until mS = 19
              //  Inc(Green_Duty)
          // EndIf
      // Case 128 To 170
            If Green_Duty > 0
              Then  mS = 0
                Repeat
                Until mS = 19
                Dec(Green_Duty)
            EndIf
      //  Case 170 To 212
            Blue_Duty = RandomVal-30
            // Then  mS = 0
              //  Repeat
              //  Until mS = 19
              //  Inc(Blue_Duty)
          // EndIf
      // Case 212 To 255
            If Blue_Duty > 0
              Then  mS = 0
                Repeat
                Until mS = 19
                Dec(Blue_Duty)
            EndIf
            Wend
         
        End
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top