Announcement

Collapse
No announcement yet.

Questions about PicKit 3.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spork Schivago
    replied
    Re: Questions about PicKit 3.

    Thanks Mariushm. I think because the questions I have now are more programming questions rather than hardware, maybe they're best suited to the Microchip Forums. My account finally got approved so I can post there now. Not 100% what forum topic I should be posting in though. There's a lot of time! I was thinking maybe the 14-Bit Core (instructions, reset, WDT, specifications...) PIC12F6xx, PIC16Fxxx, PIC16F6x, PIC16F7x topic. They got a section for the XC8 compiler that I'm using as well. Maybe I should post in there instead. Thanks for all the help! I think I'm finally getting this stuff figured out. Once I get the program finished, if you want a copy, so you can look it over, maybe provide some tips or something, I'd be more than happy to post it here for you guys.

    Leave a comment:


  • mariushm
    replied
    Re: Questions about PicKit 3.

    Yes, you can do that.

    Leave a comment:


  • Spork Schivago
    replied
    Re: Questions about PicKit 3.

    I did that with the configuration bits I believe. I set WDTE (Watchdog Timer Enable Bit) to OFF. I think I found how to set the individual bits. Hadn't read through the header file at the time I wrote the question there. From the header, I see stuff like:
    Code:
    // Register: INTCON
    extern volatile unsigned char      INTCON       @ 0x00B;
    #ifndef _LIB_BUILD
    asm("INTCON equ 0Bh");
    #endif
    // bitfield definitions
    typedef union {
      struct {
        unsigned RBIF          :1;
        unsigned INTF          :1;
        unsigned T0IF          :1;
        unsigned RBIE          :1;
        unsigned INTE          :1;
        unsigned T0IE          :1;
        unsigned PEIE          :1;
        unsigned GIE          :1;
      };
      struct {
        unsigned            :2;
        unsigned TMR0IF         :1;
        unsigned            :2;
        unsigned TMR0IE         :1;
      };
    } INTCONbits_t;
    extern volatile INTCONbits_t INTCONbits @ 0x00B;
    So I should be able to do stuff like:
    Code:
    INTCONbits.GIE = 1;
    if I want the Global Interrupt Enable bit set to 1 (enables all un-masked interrupts)

    Leave a comment:


  • stj
    replied
    Re: Questions about PicKit 3.

    make sure you disable the watchdog timer. (wdt)

    Leave a comment:


  • Spork Schivago
    replied
    Re: Questions about PicKit 3.

    I just want to make sure I got this right. I have PORTA's RA5, RA6 and RA7 set to I/O by setting the configuration bits, so they should be taken care of. For RA0, RA1 and RA3, I just need to disable the comparator and it'll switch them to digital I/O. For RA2, I see the function can be RA2, AN2 or VREF. If I disable the comparator, that leaves RA2 or VREF.

    According to the datasheet, I can manipulate VRCON (The Voltage Reference Control Register, Page 67 of the datasheet). To do this, I'd set VRCON to 0b00000000. The only bits that really matter there are bits 6 and 7, right?

    Code:
    [FONT="Times New Roman"]
    bit 7    VREN: VREF Enable bit
           1 = VREF circuit powered on
           0 = VREF circuit powered down, no IDD drain
    
    bit 6    VROE: VREF Output Enable bit
           1 = VREF is output on RA2 pin
           0 = VREF is disconnected from RA2 pin
    
    bit 5    VRR: VREF Range Selection bit
           1 = Low range
           0 = High range
    
    bit 4    Unimplemented: Read as ‘0’
    
    bit 3-0  VR<3:0>: VREF Value Selection bits 0 ≤ VR <3:0> ≤ 15
           When VRR = 1: VREF = (VR<3:0>/ 24) * VDD
           When VRR = 0: VREF = 1/4 * VDD + (VR<3:0>/ 32) * VDD
    [/FONT]
    For RA4, I am going to be using the internal clock and not any external ones, so I want to turn T0CKI off, right? Page 23 of the datasheet says:
    Code:
    [font="Times New Roman"]
    4.2.2.2   OPTION Register
    
    The Option register is a readable and writable register,
    which contains various control bits to configure the
    TMR0/WDT prescaler, the external RB0/INT interrupt,
    TMR0 and the weak pull-ups on PORTB.
    
    Note: To achieve a 1:1 prescaler assignment for
    TMR0, assign the prescaler to the WDT
    (PSA = 1). See [B]Section 6.3.1 “Switching Prescaler Assignment”.[/B]
    
    [B]REGISTER 4-2: OPTION_REG – OPTION REGISTER (ADDRESS: 81h, 181h)[/B]
    
    bit 7    RBPU: PORTB Pull-up Enable bit
           1 = PORTB pull-ups are disabled
           0 = PORTB pull-ups are enabled by individual port latch values
    
    bit 6    INTEDG: Interrupt Edge Select bit
           1 = Interrupt on rising edge of RB0/INT pin
           0 = Interrupt on falling edge of RB0/INT pin
    
    bit 5    T0CS: TMR0 Clock Source Select bit
           1 = Transition on RA4/T0CKI/CMP2 pin
           0 = Internal instruction cycle clock (CLKOUT)
    
    bit 4    T0SE: TMR0 Source Edge Select bit
           1 = Increment on high-to-low transition on RA4/T0CKI/CMP2 pin
           0 = Increment on low-to-high transition on RA4/T0CKI/CMP2 pin
    
    bit 3    PSA: Prescaler Assignment bit
           1 = Prescaler is assigned to the WDT
           0 = Prescaler is assigned to the Timer0 module
    
    bit 2-0    PS<2:0>: Prescaler Rate Select bits
    [/font]
    So I'd set OPTION_REG = 0b11010111 or am I way off on this stuff? I see I'm going to need to do stuff with INTCON as well. If I don't need to worry about a certain bit, instead of setting it to either a 0 or a 1, should I be ORing or ANDing the values I do care about with the various registers? OR it 1 to turn on one of the bits I care about or AND it with 0 to turn off one of the bits and just leave the other ones at their defaults values?
    Last edited by Spork Schivago; 12-09-2015, 11:46 AM.

    Leave a comment:


  • Spork Schivago
    replied
    Re: Questions about PicKit 3.

    Originally posted by stj View Post
    comparators are for working with analog inputs.
    Thank you. So by simply turning off the comparators, I'm setting the inputs to digital then. That's what I thought but wasn't 100% certain. There's a little bit of a learning curve here but I think I'm catching on.

    Leave a comment:


  • stj
    replied
    Re: Questions about PicKit 3.

    comparators are for working with analog inputs.

    Leave a comment:


  • Spork Schivago
    replied
    Re: Questions about PicKit 3.

    Originally posted by mariushm View Post
    On the contrary. No need to waste time with learning assembly especially with an architecture like the PIC one with its quirks that make it more difficult/different compared to other architectures.

    The free xc compiler produces quite decent code, the pro version (for which you can find patch/keygen if you look hard enough) enables some optimizations which reduce the binary size by about 10%, at best 20% - it used to be more in the past.

    The performance increase is also minimal between the generated c code and hand assembly, I'd say it really depends on what you do. You can always just do inline assembly in your C project if something is really critical.

    Besides all this, there's so many pic versions with so many options regarding ram size and flash size (storage) that unless you sell something in thousands of units, it's cheaper to just go for the next pic mcu in the series, for something like $0.1-0.2 more.
    I debated whether I wanted to go down the assembly route or not. I figured at this point in time, because I know C, stick with that to make it a little easier on me. Maybe once I get a bit better at this, I'll convert my code to assembly or something.

    Leave a comment:


  • Spork Schivago
    replied
    Re: Questions about PicKit 3.

    Originally posted by mariushm View Post
    See page 33 of datasheet: https://cdn.badcaps-static.com/pdfs/...bb83564137.pdf

    Your mcu has 2 ports, PORTA and PORTB .
    You need to set the direction with TRISA and TRISB (to either input or output) and you may need to disable the comparator like it says in the datasheet using CMCON or CMCONbits (check out the pic16f628.h file in the xc8 include folder)
    If some pins on the A port share functionality with other features, you may need to disable those features for the pins to become digital input only.

    Basically, start any project by configuring the defining _XTAL_FREQ with the frequency you're going to use, if you plan on using built in delay functions, then configure the internal oscillator bits, disable the internal watchdog timer (it's not a good idea during development) then set the ports to their proper directions and enable or disable the features i want.

    You basically have a built-in wizard which should help you set the parameters like you want and then just insert the code in your project... check Window menu > PIC Memory views > Configuration bits , set everything and then hit the generate source code to output
    Thanks for giving me the run down. I had already figured out how to set te Configuration bits and the direction of the pins. I already had _XTAL_FREQ set to 4000000 (4MHz I believe). I had defined this before any #includes, because it seems some includes actually depend on it being defined in order to work (for example, the definition of the delay functions)

    I'm still a bit confused as to what the comparators are, but from what I've read, if I just want the PORTA pins as digital I/O, I need to disable the comparators. I saw on some PICs, there's this ANSEL / ANSELH function you use to set the ports as digital or analog. Thanks for the help!

    Leave a comment:


  • mariushm
    replied
    Re: Questions about PicKit 3.

    On the contrary. No need to waste time with learning assembly especially with an architecture like the PIC one with its quirks that make it more difficult/different compared to other architectures.

    The free xc compiler produces quite decent code, the pro version (for which you can find patch/keygen if you look hard enough) enables some optimizations which reduce the binary size by about 10%, at best 20% - it used to be more in the past.

    The performance increase is also minimal between the generated c code and hand assembly, I'd say it really depends on what you do. You can always just do inline assembly in your C project if something is really critical.

    Besides all this, there's so many pic versions with so many options regarding ram size and flash size (storage) that unless you sell something in thousands of units, it's cheaper to just go for the next pic mcu in the series, for something like $0.1-0.2 more.

    Leave a comment:


  • Th3_uN1Qu3
    replied
    Re: Questions about PicKit 3.

    Same here. PICs have very limited resources which are gobbled up quickly by the C compiler. Also they have a fairly simple assembler language - no reason not to learn some of that.

    Leave a comment:


  • stj
    replied
    Re: Questions about PicKit 3.

    Originally posted by Spork Schivago View Post
    Do you know C at all?
    not me, i hit them with machinecode.

    Leave a comment:


  • mariushm
    replied
    Re: Questions about PicKit 3.

    See page 33 of datasheet: https://cdn.badcaps-static.com/pdfs/...bb83564137.pdf

    Your mcu has 2 ports, PORTA and PORTB .
    You need to set the direction with TRISA and TRISB (to either input or output) and you may need to disable the comparator like it says in the datasheet using CMCON or CMCONbits (check out the pic16f628.h file in the xc8 include folder)
    If some pins on the A port share functionality with other features, you may need to disable those features for the pins to become digital input only.

    Basically, start any project by configuring the defining _XTAL_FREQ with the frequency you're going to use, if you plan on using built in delay functions, then configure the internal oscillator bits, disable the internal watchdog timer (it's not a good idea during development) then set the ports to their proper directions and enable or disable the features i want.

    You basically have a built-in wizard which should help you set the parameters like you want and then just insert the code in your project... check Window menu > PIC Memory views > Configuration bits , set everything and then hit the generate source code to output

    Leave a comment:


  • Spork Schivago
    replied
    Re: Questions about PicKit 3.

    Originally posted by mariushm View Post
    PIC16F628A is a relatively weak microcontroller, it has very few features, little memory and ram, there's much better chips out there with more built in features like hardware i2c and spi, which could be useful.

    My favourite goto for tests is PIC16F1519 : http://www.digikey.com/product-detai...2FP-ND/2651374

    It's wide dip so it's easy to put on prototyping board, it's dip40 so it has lots of i/o pins, has 28 KB of flash (16 kwords because each word is 14 bits) so you can just code without worrying about optimizations to reduce program size, built in 16 mhz oscillator so you don't need to use external oscillator to go above 4 Mhz (as it happens with your chosen pic)

    It's kinda hard to damage a pic just by programming it with bad code. MPLAB-X is pretty good about spotting mistakes so it would be kinda hard to create a broken binary and have mplab program it to a pic and damage the pic.
    Do you know C at all? I want to set all inputs to digital and I'm not sure how to do that on the PIC16F628A. I've been reading the datasheet but all the examples are in assembly. I think I just need to set CMCON to 0x07. That should comparators off and enable the pins for I/O. Would that make them digital though? Or is there some special function or preprocessor directive I need to set that I'm not aware of?

    Leave a comment:


  • Spork Schivago
    replied
    Re: Questions about PicKit 3.

    I hooked up a USB hub and when I plug the PicKit3 into the hub, I don't have the problem. The USB Hub is powered by the USB port and I don't remove the hub. So looks like this is more than likely the polling problem you was talking about Stj. To me though, I think I'm happy with this setup

    Leave a comment:


  • Spork Schivago
    replied
    Re: Questions about PicKit 3.

    Hopefully I can some PIC in some old PCB somewheres and remove it and pop it in. Thanks!

    Leave a comment:


  • Spork Schivago
    replied
    Re: Questions about PicKit 3.

    Originally posted by stj View Post
    firmware is device specific,
    if you change the settings for a different pic chip it will re-upload the firmware to the pk3.
    then change it back to the 16f628a or whatever.

    the 25seconds thing is probably win10 polling the usb pretty slow because it's a laptop, check the power settings so it's not running in low-power mode.
    I disabled the power save mode for the device in Device Manager. Didn't change anything. Is that what you're talking about with the power settings? The USB port is powering the device, because the 3 lights stay on. Could be a polling issue I guess. I couldn't find a way to safely remove the device so I just unplug it. Perhaps that's part of the problem?

    Leave a comment:


  • stj
    replied
    Re: Questions about PicKit 3.

    firmware is device specific,
    if you change the settings for a different pic chip it will re-upload the firmware to the pk3.
    then change it back to the 16f628a or whatever.

    the 25seconds thing is probably win10 polling the usb pretty slow because it's a laptop, check the power settings so it's not running in low-power mode.

    Leave a comment:


  • Spork Schivago
    replied
    Re: Questions about PicKit 3.

    Is there a chance when I plugged it in for the first time with the bad USB cable and MPLab X updated the firmware that something might not of gotten updated properly? I mean, I remember something about the output window saying Uploading blah blah blah, Uploading blah blah blah, error connecting to device. I wish I could find away to force it to reupdate it now that we got a good USB cable there.

    Leave a comment:


  • Spork Schivago
    replied
    Re: Questions about PicKit 3.

    I believe the PicKit3 is now working. There's only one issue but it's not a big one Stj. If I unplug the PicKit3 from the PC, I have to wait 20 - 25 seconds or so before plugging it back in. If I do not wait this amount of time and plug it in, all three lights stay solidly lit and the device is never recognized as being plugged in. I even went into the registry and changed EnhancedPowerMangementEnabled to 0 as suggested in the comment section to the link you posted.

    As for the video, where they talk about disabling driver signature enforcement, am I supposed to be using MicroChip drivers? I've printed out the manual and it shows for the PicKit3, it's just recognized as a HID device under Windows. To me, that means it's supposed to use the Microsoft drivers.

    Leave a comment:

Working...
X