Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

PWM + ISP Simultaneously
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

PWM + ISP Simultaneously

by valant on Wed Nov 24, 2010 12:29 am

Hello everyone. Forgive me if this is a really noobish question, but I've been unsuccessful in searching the forums for an answer.

I'm using the ATTiny45. Here's the pinout:
Image

I want OC0A and OC1A, on pins 5 and 6, to be able to have two channels of PWM. I want to be able to use my ISP programmer with it at well. The problem lies with pin 5: MOSI refuses to work if virtually anything is connected to it while programming. I wanted to etch my PCB, so it would be impossible to remove the traces to pin 5, program the chip, put the traces back on again, etc.

Is it possible for me to change the pins the PWM outputs to? Or is there something else I can use to get this thing working?

valant
 
Posts: 9
Joined: Thu May 20, 2010 5:16 am

Re: PWM + ISP Simultaneously

by chatham on Wed Nov 24, 2010 12:53 am

Strange - what sort of things have you had connected to it?
OpenChord.org - Open Source kits to let you play Guitar Hero with a real guitar, or build your own Wii/PS3/USB controllers.

chatham
 
Posts: 144
Joined: Thu Feb 04, 2010 2:30 am

Re: PWM + ISP Simultaneously

by stinkbutt on Wed Nov 24, 2010 12:55 am

You cannot change the PWM pins. They're stuck there.

If you insist on using a different pin for PWM, you can do that, but you'll need to throw an interrupt every single time XXX happens.

What's XXX? Depends on what kind of PWM you're doing. Phase corrected, fast PWM, etc. Each event in a PWM timer's cycle, from exceeding the output compare register, to overflowing TOP on the timer, fires off an event. You manually implement PWM on a different pin by not connecting pin 5 to anything but the programmer, and then firing off the appropriate interrupts which toggle the high-low of the other pin.

Strictly speaking, that is a solution, but a bad one.

The better answer is figuring out why whatever you've got connected to pin 5 is mucking up ISP and fixing it. Can you perhaps put a DIP switch or a jumper in the way of whatever's connected to pin 5? Keep the DIP/jumper open (unconnected) while programming it and then close the switch/short the jumper.

Or just program the thing first, on a board with a ZIF socket.

Yes, I know the board's intended for a 2313. Doesn't matter. The hack to convert it to an ATTiny13, though I cannot seem to locate it, is trivially simple. Just a couple of wires going to different places. A similar hack makes it ATTiny45 compatible.
Red M&M, Blue M&M: They all wind up the same color

stinkbutt
 
Posts: 593
Joined: Wed Feb 17, 2010 2:40 am

Re: PWM + ISP Simultaneously

by valant on Wed Nov 24, 2010 1:11 am

Yeah, I don't like the sound of that. If changing pins is not a simple matter, I'd rather not mess with it. I'm sorry for not mentioning it earlier, but I'm using fast PWM.

Here's a diagram of what I currently have:
Image

I've considered using a ZIF socket, but if I had to remove the chip when I wanted to program it, there would be no point in including an ISP header on my PCB. I would really prefer to keep the ISP header.

Another solution would be to add a flip-switch between the ISP MOSI wire and the transistor...

valant
 
Posts: 9
Joined: Thu May 20, 2010 5:16 am

Re: PWM + ISP Simultaneously

by stinkbutt on Wed Nov 24, 2010 1:23 am

Well, I have no idea why that won't work. But you might try switching out the PNP for an NPN. Maybe pin 5 ends up sinking current when MOSI is low, fooling it into thinking MOSI's actually high.

Also, can anyone tell me if this diode is hooked up right? I thought the diode goes in parallel with an inductive load, not in parallel with the transistor.

Yeah, shouldn't it be like this?

Image
Red M&M, Blue M&M: They all wind up the same color

stinkbutt
 
Posts: 593
Joined: Wed Feb 17, 2010 2:40 am

Re: PWM + ISP Simultaneously

by stinkbutt on Wed Nov 24, 2010 1:26 am

Which brings up another issue: There's no R(B) resistor going to the base of the PNP. That might be problematic, especially since you're using a garden-variety BJT instead of a FET. Perhaps you try throwing in a resistor at the base of the transistor.
Red M&M, Blue M&M: They all wind up the same color

stinkbutt
 
Posts: 593
Joined: Wed Feb 17, 2010 2:40 am

Re: PWM + ISP Simultaneously

by valant on Wed Nov 24, 2010 1:50 am

Whoops, I'm sorry, my diagram is wrong! I did put a resistor on the transistor's base, I forgot to draw it.

Your positioning for the protection diode makes a lot more sense than mine. I've altered it to match.

I will try using an NPN transistor.

valant
 
Posts: 9
Joined: Thu May 20, 2010 5:16 am

Re: PWM + ISP Simultaneously

by valant on Wed Nov 24, 2010 2:25 am

Alright, I tried the NPN transistor. The motor works, but the ISP still won't program it.

I greatly appreciate your help.

valant
 
Posts: 9
Joined: Thu May 20, 2010 5:16 am

Re: PWM + ISP Simultaneously

by zener on Wed Nov 24, 2010 2:53 am

Try a fet

zener
 
Posts: 4567
Joined: Sat Feb 21, 2009 2:38 am

Re: PWM + ISP Simultaneously

by valant on Wed Nov 24, 2010 3:18 am

Hmm, I don't have any FETs with me. That's a MOSFET, right? How does it differ from a transistor?

valant
 
Posts: 9
Joined: Thu May 20, 2010 5:16 am

Re: PWM + ISP Simultaneously

by stinkbutt on Wed Nov 24, 2010 3:46 am

MOSFET, JFET, whatever. (Here a FET, there a FET, everywhere a FET FET.)

They're all still transistors, but unlike BJT's, FET's draw virtually no current through their base. Though it's not called a base in the case of a FET it's called gate instead. That way you don't have to worry about the trickle current through the transistor.
Red M&M, Blue M&M: They all wind up the same color

stinkbutt
 
Posts: 593
Joined: Wed Feb 17, 2010 2:40 am

Re: PWM + ISP Simultaneously

by zener on Wed Nov 24, 2010 3:59 am

Radio shack carries one, ONE... IRF510, N channel. Works like NPN, just no base resistor.

zener
 
Posts: 4567
Joined: Sat Feb 21, 2009 2:38 am

Re: PWM + ISP Simultaneously

by Entropy on Wed Nov 24, 2010 11:14 am

Other option would be to change the base resistor - what value are you using?
Entropy
 
Posts: 472
Joined: Tue Jan 08, 2008 12:43 am
Location: Owego, NY USA

Re: PWM + ISP Simultaneously

by valant on Wed Nov 24, 2010 11:43 am

I'm using a 1K ohm resistor on the base

valant
 
Posts: 9
Joined: Thu May 20, 2010 5:16 am

Re: PWM + ISP Simultaneously

by valant on Wed Nov 24, 2010 1:42 pm

Heh. Bobba FET.

I picked up the IRF510 from Radio Shack. Base resistor removed, and voila! It works! This has been bothering me for days, thank you so very much.
Replacing my transistors with MOSFETs is definitely a solution.

One more thing: Radio Shack wants a small fortune for each one, and 1.5 amps is a little overkill.

Here's MOSFET I believe I could use instead:
http://www.mouser.com/ProductDetail/Fairchild-Semiconductor/FQP4N50_Q/?qs=sGAEpiMZZMvECErq9cesgAC6wr/2Ze3wB3l1G7Vitcw%3d

It's an N channel, and it's datasheet shows that is has an 'extra' diode in it:
Image

I'm pretty sure that the diode is there for polarity protection, similar to where my protection diode was originally. Is this the case? Or does this diode make the part incompatible?
OR, is there something else that makes this part unusable for PWM?

Entropy wrote:Other option would be to change the base resistor - what value are you using?

I apologize for repeating what I said last post. I was using a 1K ohm resistor. I hadn't calculated the value, though; I just threw a resistor in there much in the same way I do when I use pull-up/down resistors.

valant
 
Posts: 9
Joined: Thu May 20, 2010 5:16 am

Please be positive and constructive with your questions and comments.