Skip to main content
Topic: PicProgrammer v2 for BusPirate v4 Development (Read 38554 times) previous topic - next topic

Re: Re: Where to got a PicProgrammer adapter for BusPirate?

Reply #30
It will go pop and make magic smoke if you got it right :)
Got a question? Please ask in the forum for the fastest answers.

Re: Re: Where to got a PicProgrammer adapter for BusPirate?

Reply #31
[quote author="ian"]It will go pop and make magic smoke if you got it right :)[/quote]
Riiiiiight... I see what you did there :D

Re: Where to got a PicProgrammer adapter for BusPirate?

Reply #32
OK, finally had time to fiddle with this. The mosfet works really well with 3.3v gate voltage, I was able to switch it on/off by using the AUX pin. Then I laid out the basic boost circuit and hacked continuous ADC measurement function for a quick and dirty way to try it out. Here is the hacked function:
Code: [Select]
// hacked for smps mode
void bpADCCprobe(void)
{ unsigned int adc, PWM_dutycycle, V_out;

    consumewhitechars();
    V_out = getint(); // Output voltage in centivolt
if (V_out>1300){ // Upper limit of our ADC
return;
}
    PWM_dutycycle = 128-(500/V_out); // Duty cycle in 7 bits
V_out = V_out*45/58; // Change to 1024 bit ADC reading to make comparison faster

    //assign pin with PPS
    BP_AUX_RPOUT = OC5_IO;
    OC5R = PWM_dutycycle;
    OC5RS = 0x7F; // Set PWM period to 125 KHZ
    OC5CON2 = 0x1F;
    OC5CON = 0x1C06;                 

while(!UART1RXRdy()) // wait for keypress
{ AD1CON1bits.ADON = 1; // turn ADC ON
adc = bpADC(BP_ADC_PROBE);
AD1CON1bits.ADON = 0; // turn ADC OFF
if(adc > V_out){ // if output voltage is higher than requested voltage
OC5R = 0x00; // turn PWM off temporarily
}else{
OC5R = PWM_dutycycle; // othervise resume operation
}
}
UART1RX();
bpWline(""); // need a linefeed :D
}
It compiles fine, I export it and upload it with the bootloader. However, when I try to run it, my BP turns off. I have to reset it. I tried the code without plugging it in, again the same problem, so I was not able to test if I have an output on AUX pin. I don't know what is causing the problem and didn't have time to debug properly. Tomorrow I'll try to move the code to servo function and use the settings there.

Re: Where to got a PicProgrammer adapter for BusPirate?

Reply #33
Upppsssss, I do see a bug now:
Code: [Select]
PWM_dutycycle = 128-(500/V_out);   // Duty cycle in 7 bits
Should be corrected, actual formula is:
Code: [Select]
PWM_dutycycle = (1-500/V_out)*128;

Re: Where to got a PicProgrammer adapter for BusPirate?

Reply #34
So apparently I had two bugs on the code: one is the one I talked about in my previous message (which was the reason why BP was turning itself off, it basically short circuits the device), the other was getint() function. I changed it to getnumber() function which also does the range test, now it works really good. The voltage readout from my voltmeter is about 40mV higher than my request but that is OK. Here is the hacked function, also I'm attaching the hex file for others to try:
Code: [Select]
// hacked for smps mode
void bpADCCprobe(void)
{ unsigned int adc, PWM_dutycycle, V_out;

    consumewhitechars();
    V_out = getnumber(0,550,1300,0); // Output voltage in centivolt

    PWM_dutycycle = 128-(64000/V_out); // Duty cycle in 7 bits
V_out = V_out*45/58; // Change to 1024 bit ADC reading to make comparison faster

    //assign pin with PPS
    BP_AUX_RPOUT = OC5_IO;
    OC5R = PWM_dutycycle;
    OC5RS = 0x7F; // Set PWM period to 125 KHZ
    OC5CON2 = 0x1F;
    OC5CON = 0x1C06;                 

while(!UART1RXRdy()) // wait for keypress
{ AD1CON1bits.ADON = 1; // turn ADC ON
adc = bpADC(BP_ADC_PROBE);
AD1CON1bits.ADON = 0; // turn ADC OFF
if(adc > V_out){ // if output voltage is higher than requested voltage
OC5R = 0x00; // turn PWM off temporarily
}else{
OC5R = PWM_dutycycle; // othervise resume operation
}
}
// Cleanup
OC5R = 0;
    OC5RS = 0;
    OC5CON2 = 0;
    OC5CON = 0;   
UART1RX();
bpWline(""); // need a linefeed :D
}

In the final version ADC interrupt should be enabled and the output voltage check and pulse adjustment should be done in the interrupt. But yeah, we now can have a boost converter shield for PIC programming and other purposes. :)

PS. No magic smoke during these tests. Damn, I really wanted to earn that magic smoke badge from Adafruit! :P

 

Re: Re: Where to got a PicProgrammer adapter for BusPirate?

Reply #35
Nice work! I saw this really late last night and wanted to suggest a short turning it off, but it looks like you got it yourself.
Got a question? Please ask in the forum for the fastest answers.

Re: Re: Where to got a PicProgrammer adapter for BusPirate?

Reply #36
[quote author="ian"]Nice work! I saw this really late last night and wanted to suggest a short turning it off, but it looks like you got it yourself.[/quote]
Yeah, apparently my duty cycle was so big that I was drawing too much current and basically shorting the device. Will take some pictures for my results, PWM wave with OLS, some different values tried etc. and post them here. I guess we have a board design for this in SVN (ok, looked it up, it is for the old version). I can try to whip up a schematic too if you want. Currently I don't have sth to switch voltage on/off, it may be a good idea to put sth right after the output of boost converter to switch it.

Re: Where to got a PicProgrammer adapter for BusPirate?

Reply #37
OK, so here are the pictures, sorry, a bit blurry because the lighting in my room is not good enough for my cellphone camera. First one is the PWM signal measured. I tried to catch the skipped pulses too but no luck there...
[attachment=2]
Second one is my test setup on my desk: BPv4 on the left, breadboarded circuit in the middle, multimeter connected to the output is on the right.
[attachment=1]
I did a couple of tests, but the best picture that displays serial console is the one where output voltage is set to 13 V. Multimeter output is 13.2 V which is strange as yesterday the difference was only 40 mV but now it is about 200 mV.
[attachment=0]
Usage is pretty easy, you turn on power supplies with W, then D (as I hacked continuous ADC mode). After this you have to enter a voltage in cV. To exit this mode, you just have to press a key. Ramp up speed is really good, it reaches 13 V in less then a second.

I will clean up my code a bit, so that when SMPS is on, other functions can still be used. Currently this is really limiting.

Re: Re: Where to got a PicProgrammer adapter for BusPirate?

Reply #38
Nice job! I'll post a little preview on the blog :)
Got a question? Please ask in the forum for the fastest answers.

Re: Where to got a PicProgrammer adapter for BusPirate?

Reply #39
I did some work, I've created a new library (smps.c and smps.h) which contain the bpSMPS() function that I'm running. I've included the ADC interrupt, it still blocks the command line but I'll do the change once I finish drawing the schematic later today. I had to make some additions to procMenu.c, I've assigned the bpSMPS() function to M for sMps (I searched for a while, you might want to change it). It has the same license header as the rest. I'm committing all the files, I put a little if define check to include the code only with v4 hardware. I'm hoping that I didn't break anything, but if I did, let me know.

Re: Re: Where to got a PicProgrammer adapter for BusPirate?

Reply #40
OK, blocking issue is solved, I tested out UART communication while boost circuit was working. Also initial schematic is uploaded.

Re: PicProgrammer v2 for BusPirate v4 Development

Reply #41
Nice work, thank you. Where did you put the schematic? I have not been able to find it.
Got a question? Please ask in the forum for the fastest answers.

Re: PicProgrammer v2 for BusPirate v4 Development

Reply #42
[quote author="ian"]Nice work, thank you. Where did you put the schematic? I have not been able to find it.[/quote]
It is under Bus_Piratehardware-otherPiratePICprog, named as bp_pic_programmer_v2.sch

There are 2 unconnected signals (PWM and VPPEN), did a few corrections just now. For being able to use the same binMode messages, maybe it is better to move PWM to AUX1 or AUX2. I'll also add a binMode message for PiratePICProg. A 2 byte message where the first 4 bits tell it to start SMPS, remaining 12 bits give the voltage request: max value supported is 1300 cV = 13 V (at least in the terminal, with getnumber function), that is a 11 bit number, with 12 bits, we can go up to 4095 cV = 40 V, but we have to change the value of the feedback resistor from 20k to something larger for higher voltages than 13 V.

After schematic is finalized, I'll start routing.

Re: PicProgrammer v2 for BusPirate v4 Development

Reply #43
Looks great to me.

In v1 (let's call it v3 now, and this v4...) we used AUX for VPPEN, which is why we couldn't do the simple SMPS style. AUX0 is already PWM, so that makes sense, but if it is easier with binmode it is only 1 or 2 lines of code to move it elsewhere. It is really up to you which pin is best :)

I would keep it locked at 13volts for now, that's enough for most stuff.

In a future revision maybe we can add a AVR high-voltage programming header for fuse rescue.
Got a question? Please ask in the forum for the fastest answers.

Re: PicProgrammer v2 for BusPirate v4 Development

Reply #44
[quote author="ian"]In v1 (let's call it v3 now, and this v4...) we used AUX for VPPEN, which is why we couldn't do the simple SMPS style. AUX0 is already PWM, so that makes sense, but if it is easier with binmode it is only 1 or 2 lines of code to move it elsewhere. It is really up to you which pin is best :)[/quote]
OK, lets use AUX0 for VPPEN and PWM with AUX1. It is just one simple change in code so no worries there.

[quote author="ian"]I would keep it locked at 13volts for now, that's enough for most stuff.[/quote]
So limited to 13 V it is.

[quote author="ian"]In a future revision maybe we can add a AVR high-voltage programming header for fuse rescue.[/quote]
OK, got that. Checking out high voltage programming as I have no knowledge. Seems like nearly all the signals are the same except reset pin, which needs 12V?