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.

PIC speeds - which PIC to use?

Status
Not open for further replies.

G33K

New Member
Hi there, I'm just starting a little project involving a PIC, some LEDs and a bit of PWM cleverness. Basically, I want to modify the Poi I built to add more colours + flashing and strobing effects. Here's a shot of them as they are at the moment :

**broken link removed**

I've posted some stuff about this on other forums, but not really got anywhere. I'm very new to PICs, but I've done a little assembly and a LOT of C/C++/VC++ coding before. Basically, I want to run 3 PWM channels to flash red, green and blue LEDs to reproduce a large range of colours. I also want to make strobing effects and colour changes and a load of other effects. Here's a few :

**broken link removed**

...now come the problems :

1) I want to run all this off 4xAAA batteries, and if it's possible, avoid using resistors to drop the voltage down. Afterall, PWM is supposed to make things more efficient isn't it?

2) I'm not 100% sure, but I think I need my PWM signal running at ~100KHz. Poi are swung around fairly fast, so too slow and the colours will seperate and you'll see the strobes seprate which is an undesirable effect. I took a vid of myself doing some Poi using my digicam earlier. It takes movies @ 15fps. Now knowing that and the length of the chains, we should be able to calculate how fast the things move and therefore, the minimum speed we need to do the PWM so you can't see it.

Here's what I've got :

Chain length : ~0.8 m (that's from the handle to the tip of the LED tube)
Frame Rate : 15 fps
Angle covered between frames : ~45°
Circumference of the circle the Poi spin through = 2*Pi*r = 5.03 m
Distance travelled by the Poi between frames = circumference * angle / 360 = 0.63 m
Approximate speed of Poi = distance / time = 0.63 / (1/15) = 9 m/s

So what kind of seperation will there be between flashes?

100Hz => 94.2 mm
1KHz => 9.42mm
10KHz => 0.94mm
100Khz => 0.094mm

Okay, that's enough for one post.. So what PIC would you recommend to run off a 5v supply to produce 3 PWM signals at the kind of speeds I'm after? Let me know what you think! All comments / suggestions are most welcome! :)
 
Because the human eye is fairly slow you probably don't need to worry too much about people seeing flicker. In the dark the eye is even slower than in bright light. If you're worried using a DAC instead of PWM or a capacitor to integrate the PWM should fix the problem.

Since you know C you might as well get one of the bigger PICS that are designed for C. You could also look into the AVR uC which is designed for C and have a GCC compiler available.

You will still need resistors to limit the Current to the LEDs to keep from damaging them. You could use a switching regulator to step down the voltage to close to the turn on voltage of the LED's to reduce the power dissipation.

Hope this helps.

Brent
 
Spinning sticks are worse than the "human eye response" limits. You need a pretty high PWM speed or a 50% brightness in, say, red will show up as full brightness red "spokes" with unlit areas in between when spun fast.

All the PICs in small pkgs only have 2 PWM outputs, so you'd need to do at least 1 color in software. The PIC18F series runs at a 10MHz instruction cycle, twice as fast as the older ones, so that may be your best best. I'd say 100kHz looks nearly possible but it depends on how many shades you want to be able to create. There are good C compilers for the PIC18 too, it has an expanded instruction set which is more compiler-friendly.

Atmel has some with 3 or more PWM outputs. I don't know much about them and you'd need to check if they come in a pkg useful to you.

PIC pins do have a substantial output resistance as well as a rated current output. It's possible (maybe) to run it without resistors, but I would not bet on it from the beginning. Resistors are cheap & small anyways. If you want to drive more than one LED per color, you might NEED an external transistor.

3xAAA will produce enough voltage to drive your LEDs if you use alkaline.
 
Thanks for the suggestions guys. Sounds like an 18Fxxx is the way forward then.

I don't want to use alkaline batteries because I want these things to be rechargeable.. so 4xAAA NiMH's are what I'm going with.

If I'm going to use reisitors, then using some capacitors as well would make PWM much easier wouldn't it? I mean, with some caps in there, I should be able to run at much slower frequencies right?
 
Caps won't do much to make PWM easier. If you're using a driver which pulls high and low (a PIC pin will, a MOSFET won't), then you'll burn a lot of power.

In my experience, caps don't work well with LEDs, due to their nonlinear IV curve. See, you might have an LED which doesn't turn on below 3V and can't be driven above 3.5V. And say you want a very rough 30% current (luminous intensity) regulation, that might translate into only an allowable 0.1V ripple on the caps. That's only a small voltage window for energy storage. So they'd need to have an unusually large capacitance and/or high frequency or it's only going to slightly smooth out the turn on/off times. Being a current-based situation, inductors are often a more appropriate filter, but in that case you'd need a diode in the right place or a driver which pulls both high and low. It's a bit more complicated.

So, I'd recommend first trying to get what you want from running a PWM as fast as you can.
 
Actually the critical factor now is how much current/voltage do the LEDs take. With that, we can probably figure out what to start building.

Beware the flashy sticks, BTW... very hard for the eye to track motion of a strobing object. So swinging it could be something of a challenge.

4xAAA is very close to the PIC's max operating voltage of 6V, by the way. I don't recall what the unloaded voltage can go up to, but it's probably enough to latch up the PIC.

Another fancy add on, by the way- they make accelerometers, both linear and angular, that could create very cool variations. You could calculate the angular speed, and use it to adjust the color fader so that it makes a full rainbow over a full circle and keeps it oriented in a basically consistent direction. The software-driven PWM may not leave much processing time for anything else though.
 
Oznog said:
Actually the critical factor now is how much current/voltage do the LEDs take. With that, we can probably figure out what to start building.

When I was developing the 'sticks' you see in the photo above, I measured the current flowing. From 3xAAA batteries, running 4xSuper-Bright LEDs, I was getting something in the region of 300mA.

Oznog said:
Beware the flashy sticks, BTW... very hard for the eye to track motion of a strobing object. So swinging it could be something of a challenge.

Ah, but Poi aren't sticks.. they're traditionally balls on string. Mine are slightly different - tubes on chain, but essentially it's the same. They have handles you poke your fingers through :

**broken link removed**

So seeing or not seeing them isn't a problem for the spinner - I can do it with my eyes closed! ;)


Oznog said:
4xAAA is very close to the PIC's max operating voltage of 6V, by the way. I don't recall what the unloaded voltage can go up to, but it's probably enough to latch up the PIC.

I just put the batteries on charge and after taking them off and measuring the voltage with a multimeter, we get 5.53v which should be alright shouldn't it?

Oznog said:
Another fancy add on, by the way- they make accelerometers, both linear and angular, that could create very cool variations. You could calculate the angular speed, and use it to adjust the color fader so that it makes a full rainbow over a full circle and keeps it oriented in a basically consistent direction. The software-driven PWM may not leave much processing time for anything else though.

Yeah, the same thought had crossed my mind. I don't know how easy it'd be to do, but if it worked.. :D

I think I'll take it a step at a time - first I need to try and get the PWM working! How can I go about calculating how much current / voltage the LEDs take then?
 
What about using hardware PWM? The 16F7X7 chips have 3 PWM channels so perhaps I could use those.. ? That would leave a lot more time for doing other cool stuff like playing with accelerometers :)

I've been trying to make sense of the Datasheets, but I the PWM example they give seems to imply that only CCP1 actually outputs a PWM signal? I think I've missed something / confused myself :?
 
Yes, thanks for that.. I'd noticed it before and a lot of what's going on there is just what I need. The difference is that the guy over there is using static LEDs - they're not moving so he can get away with MUCH lower PWM speeds :( I think I need to use a faster PIC if I'm to do it in software... ?
 
Wow! 16F7X7 DOES have 3 pwms in a 28 pin DIP!

I didn't realize there was such a part. I was looking for one for a similar project and didn't find it- in their infinite wisdom, Microchip doesn't even list number of PWMs in the selection guides. All the 3 PWM parts I'd seen were in high pin count SMT pkgs.

Hardware PWM is undoubtedly the way to go if it's available!

With some manual searching, I saw the PIC18F2331 & PIC18F2431 were 18F series with 3 PWM in a 28 pin DIP. That would allow for a really, really smoking 10 MHZ instruction speed... but it's probably overkill at that point. The PIC18F series is more C compiler friendly, but at least the HiTech PICC compiler I used doesn't even support the 2331 or 2431. Something to research. There are C compilers for PIC16 series, they are also limited in which PICs it supports.
 
Not too bothered about the ability to code in C.. assembly is much more efficient + a bigger challenge :p

One thing I can't figure out from the data sheets is whether/how you can set each PWM channel to different frequencies / duty cycles etc... ?
 
The PWMs on the chips I used all reference the same timer2 for PWM period, thus they must be the same freq. That's ok for your LED pulser though.

CCPxL and CCPxCON registers set the PWM period "x" is the number, 1, 2, 3.
 
Ah yes, I was thinking frequency when what I need to adjust is duty cycle :)

Okay, that sounds really good - think I'll go order some samples so I can start playing. Couple more questions for you though...

1) I'll be controlling several LEDs from each PWM channel so I'll need some kind of transistor or MOSFET or something. What would you recommend to
a) Drive 4 LEDs per channel
b) Drive 1 Luxeon per channel
2) What sort of resonator should I use? The documentation mentions a few options and I've no idea what the pro's/con's of each are.. ?

Thanks very much for the help so far - very much appreciated! :)
 
Just use a crystal. If it's a PIC18, you must use the 4x mode to get 40MHz so you need a 10MHz crystal. PIC16 series always operates at crystal freq. You may or may not need a pair of small ceramic caps to get it to oscillate cleanly.

Use an N-channel MOSFET and invert your duty cycle calculations. Actually, P-channel will work OK since you've got no regulator and the battery voltage is the same as the high logic level. Get MOSFETs with a low "rds on", and you should be able to get a small, light pkg without heatsinking. I-Pak (TO-251, TO-251AA) is a great little pkg.

You must use a resistor with each LED or series string of LEDs. It needs to drop a minimum of 20% or so of the voltage to effectively regulate the current (LED i/v curves are sharp and unpredictable). I would recommend you size it so that you're at max continuous current, rather than max pulse current, for the LEDs when the MOSFET is on.

Luxeons create an unbelievable amount of light, but they do take a lot a lot of power for an LED and require proper heatsinking. Also, AAA NiMH won't power these for all that long.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top