# Simple Led PWM driver

#### LostInSpace

Joined Mar 16, 2010
24
most off the Slave Modul will use PICAXE 08M

8 Pin 2 for power and 2 for seriel com..

1 Pin read Temp from 18S20

1 Pin for light sensor

This slave modul is a type off remote I/O board on a 200m long network

The main task of the slave is to wait for an orders-MAIN system and provide answers back

I have no way of putting it to create PWM, because serial connection

Last edited:

#### SgtWookie

Joined Jul 17, 2007
22,210
most of the Slave Modules will use a PICAXE 08M

8 Pins are used as:
2 for power (Vdd/GND).
2 for serial communication.
1 Pin read Temp from 18S20.
1 Pin for light sensor
This slave module is a type of remote I/O board on a 200m long network
The main task of the slave is to wait for an orders-MAIN system and provide answers back.
I have no way of putting it to create PWM, because of the serial connection.
OK, so you have a master module somewhere (in the house, I suppose) and then a bunch of slaves, or just one?
It seems to me that you only need one slave for the light sensor and temperature. The remaining slaves simply need to listen for commands, and control the LEDs, right?

#### thatoneguy

Joined Feb 19, 2009
6,359
How will the serial work if one of your rechargeable solar cells fails?

Seems this is over complicated for the task by far, unless it is for an educational project. Even then, there are issues, such as the power mentioned above, along with other failure modes.

#### LostInSpace

Joined Mar 16, 2010
24
OK, so you have a master module somewhere (in the house, I suppose) and then a bunch of slaves, or just one?
It seems to me that you only need one slave for the light sensor and temperature. The remaining slaves simply need to listen for commands, and control the LEDs, right?
Yes i have a master, see the attachment

I have now plan for 16 slave

There will be more board with light and temp. sensor in the system

all slave board is base the same and run the same code just the ID is diff
not all will have the same sensor on

slave will be build off to part (1 PIC & the serial circuit) on top part ( sensor and light ) this will make it easy to make many

SLAVE ALWAYS only listen for command and what master want

Replay from slave is set by delay use the unit ID

#### Attachments

• 28.5 KB Views: 18

#### LostInSpace

Joined Mar 16, 2010
24
How will the serial work if one of your rechargeable solar cells fails?

Seems this is over complicated for the task by far, unless it is for an educational project. Even then, there are issues, such as the power mentioned above, along with other failure modes.
This system is only for personal use at home

Solar cell will be around 400 watt from the solarcell
down to 400A 24V Battery split in 2 bank

Solar system have solar control and a
monitoring system for the power load

The only connection to public power net is that if battery pack go in low power stat, the system get automatic power for power supply

Last edited:

#### SgtWookie

Joined Jul 17, 2007
22,210
I received/replied to your PM; unfortunately my time is very short at the moment - I'll have to revisit this perhaps later this evening.

#### SgtWookie

Joined Jul 17, 2007
22,210
Yes i have a master, see the attachment

I have now plan for 16 slave
Do you mean 16 slaves just for the LEDs, and then more for secondary functions such as ambient light and temperature?

There will be more board with light and temp. sensor in the system
OK, I guess you answered that question.

all slave board is base the same and run the same code just the ID is diff
not all will have the same sensor on
I could see you using basically (sic) the same code, simply calling different subroutines for the various functions the slave provides, but having all the boards being designed the same might pose a problem for what kind of peripherals you can use - unless each board will have a "breadboard" or "prototyping" area.

slave will be build off to part (1 PIC & the serial circuit) on top part ( sensor and light) this will make it easy to make many

SLAVE ALWAYS only listen for command and what master want
So... how are the temperature and light sensors going to report back to the master? You will need some sort of interrogate - reply scheme for those.

You might also consider having a handshake of sorts for the slaves that are just running the LEDs; for example send a slave a command to turn the LEDs to 25%, and the slave reports back that the LEDs are now at 25% or report an error/malfunction; if the master doesn't receive a reply in the allotted time, it can report or log the error and continue to the next slave. This could also make adding more slaves easier in the future, as you could have the master "auto-detect" how many slaves are in the system, and determine what type of slave it is by a pre-programmed code in the slave.

Replay from slave is set by delay use the unit ID
OK, now you are saying that the slaves ARE going to reply, which makes more sense.

#### LostInSpace

Joined Mar 16, 2010
24
Do you mean 16 slaves just for the LEDs, and then more for secondary functions such as ambient light and temperature?
some board will have 1 function and other will have more

the master will know what function's all board have

slave board function/id is storage in main in 8 byte = 1. ID 2. function 3. status for function 4. temp 5. light sensor. 6-8 spare

I could see you using basically (sic) the same code, simply calling different subroutines for the various functions the slave provides, but having all the boards being designed the same might pose a problem for what kind of peripherals you can use - unless each board will have a "breadboard" or "prototyping" area.
I have 5 pin on the slave that will be connected to a standard board with light drive / light sensor / temp sensor, this will not all have the same part

So... how are the temperature and light sensors going to report back to the master? You will need some sort of interrogate - reply scheme for those.

You might also consider having a handshake of sorts for the slaves that are just running the LEDs; for example send a slave a command to turn the LEDs to 25%, and the slave reports back that the LEDs are now at 25% or report an error/malfunction; if the master doesn't receive a reply in the allotted time, it can report or log the error and continue to the next slave. This could also make adding more slaves easier in the future, as you could have the master "auto-detect" how many slaves are in the system, and determine what type of slave it is by a pre-programmed code in the slave.
master / slave communication

Master call slave bye (ID, Function code, value)
slave report back with (ID+128,function code, value)
Master call slave bye (ID, Function code(OK), NULL)
slave report back with (ID+128,function code(OK), NULL)

Function code can be( SET, GET, READ, WRITE, TEMP, LIGHT, OK )

every 5-10 min master make a check on all slave in the system

If the master not have possible to connect a slave i 1 hours error BIT set for the slave ID

#### SgtWookie

Joined Jul 17, 2007
22,210
I need the specifications for your LEDs, and the resonator frequency that you will be using for the PIC LED controllers.

Typical Vf @ current
Maximum current rating

What I am looking at is using the PWMout command on pin 2 (the only PWMout pin available on the PIC08M) to drive the gate of a MOSFET; the MOSFET switches current on and off through an inductor, and the inductor discharges its' current through a diode to supply greater than the 5v to two LEDs in series. A capacitor is used across the LEDs to keep the current fairly constant.

This is pretty simple, involving few parts, and you will have more control over the amount of light produced than simply 25% or 50% brightness.

Right now, I'm using a model for blue LEDs that are rated for a typical Vf of 3.4v @ 30mA, and it looks pretty good.

Have a look at the attached schematic and simulation. V(n003) is the voltage on top of C1. I'm using 10kHz PWM at 10% duty cycle. Note that this is simplified, in a real circuit you would need a resistor between the gate and the PIC I/O pin, and you would need a couple of capacitors on the input 5v side.

#### Attachments

• 61 KB Views: 16

#### LostInSpace

Joined Mar 16, 2010
24
I need the specifications for your LEDs, and the resonator frequency that you will be using for the PIC LED controllers.

Typical Vf @ current
Maximum current rating

What I am looking at is using the PWMout command on pin 2 (the only PWMout pin available on the PIC08M) to drive the gate of a MOSFET; the MOSFET switches current on and off through an inductor, and the inductor discharges its' current through a diode to supply greater than the 5v to two LEDs in series. A capacitor is used across the LEDs to keep the current fairly constant.

This is pretty simple, involving few parts, and you will have more control over the amount of light produced than simply 25% or 50% brightness.

Right now, I'm using a model for blue LEDs that are rated for a typical Vf of 3.4v @ 30mA, and it looks pretty good.

Have a look at the attached schematic and simulation. V(n003) is the voltage on top of C1. I'm using 10kHz PWM at 10% duty cycle. Note that this is simplified, in a real circuit you would need a resistor between the gate and the PIC I/O pin, and you would need a couple of capacitors on the input 5v side.

Uf typ 3.3V / max if = 30 ma
10000 mcd max

resonator frequency =10k

Then you want the 08M to make the PWM signal ???
that can maybe give some problem when the PIC shut read the TEMP it take op to 500ms

Both i can put 2 08M on each board no problem in that

08M is cheap only 3$+ shipping Last edited: #### SgtWookie Joined Jul 17, 2007 22,210 Only 10kHz for the resonator? Then forget PWM from the microcontroller; the inductor would have to be much too large. If you were using a 4MHz resonator, then you could use PWM from the 08M. Thread Starter #### LostInSpace Joined Mar 16, 2010 24 Only 10kHz for the resonator? Then forget PWM from the microcontroller; the inductor would have to be much too large. If you were using a 4MHz resonator, then you could use PWM from the 08M. sorry the PWM shut be 10Khz The resonator/speed on the Picaxe 08M 4Mhz can also be 8Mhz both the there shut be some software change The PICAXE 08M make PWM 10khz 10% with command PWMOUT 2, 99,40 Last edited: #### SgtWookie Joined Jul 17, 2007 22,210 OK, if you're using 4MHz or 8MHz, then you could use the 08M's PWM output to control a MOSFET's gate. You can also use the ADCsetup and readADC or readADC10 functions to monitor the voltage output at Sense; I=E/R, so if R=0.1 Ohm, 20mA current through R1 would produce 0.02 Amperes X 0.1 Ohms = 2mV. R1 could be increased for a higher voltage output to keep the parts count down; if R1 were 10 Ohms then 20mA current would produce 0.02A x 10 Ohms = 0.2V (200mV) at Sense. Thread Starter #### LostInSpace Joined Mar 16, 2010 24 OK, if you're using 4MHz or 8MHz, then you could use the 08M's PWM output to control a MOSFET's gate. You can also use the ADCsetup and readADC or readADC10 functions to monitor the voltage output at Sense; I=E/R, so if R=0.1 Ohm, 20mA current through R1 would produce 0.02 Amperes X 0.1 Ohms = 2mV. R1 could be increased for a higher voltage output to keep the parts count down; if R1 were 10 Ohms then 20mA current would produce 0.02A x 10 Ohms = 0.2V (200mV) at Sense. Ok I get some part to make a test circuit and try to have communication code together with the PWM code if not i just add 1 more 08M to original setup thy are cheap to use #### Wendy Joined Mar 24, 2008 21,906 PWM does not make the LEDs more efficient as you stated in post #16, just be aware of this. #### SgtWookie Joined Jul 17, 2007 22,210 Bill, What I'm talking about here is using his PICs' PWM module to drive the gate on a MOSFET; the MOSFET is the switching portion for a DC-DC boost converter. This is much more efficient than simply using PWM along with a current limiting resistor, as the majority of the power in the circuit is dissipated in the LEDs. There are some losses through the Schottky diode, the current sense resistor, the MOSFET and the inductor (in that order), but really much less than what a current limiting resistor would mean - besides, with this scheme, the two LEDs are operated in series; if need be, LostInSpace could add even more LEDs in series if they later discovered they needed to. Of course he would need more power input to drive the additional series LEDs, but the circuit would actually become more efficient. #### nickelflipper Joined Jun 2, 2010 280 Curiosity has the cat here on how 5v ttl levels are going to work on a 200m network? You would have to double that distance because of the return signal (assuming single ended string). Anything less than 0.7Vdd upon the return leg to the master, and will not have a valid "high" level. If the slave device's were upgraded to one that has both a built in Usart (i.e use RS232 12V levels), and hardware PWM, then costs could be saved on wiring and extra 08M's? #### SgtWookie Joined Jul 17, 2007 22,210 Good point, Nickelflipper. Decided to track down the communications protocol these uC's are using; it's I2C. Specs: http://www.i2c-bus.org/fileadmin/ftp/i2c_bus_specification_1995.pdf Surprise - it's a bus specification, and they're not very specific about bus length, but they do mention that maximum capacitance for either the data or clock bus is 400pF; and if the length of the bus is 10cm or more, a specific layout needs to be used to prevent crosstalk between the data and clock buses (basically, Vss between them). It does mention twisted pair, but that's dubious. So, I looked up the Cat5 specification; most of us are familiar with the 4 twisted pairs, right? http://en.wikipedia.org/wiki/Category_5_cable 52pF per meter - so, it's going to be a pretty short run. I have a feeling that our OP isn't going to like this news... about 7.7 meters of cat5 cable, and the limit is hit - without even having a slave hooked up. So, each board is going to need line differential line drivers and receivers; properly terminated of course. This could get expensive in a hurry. #### nickelflipper Joined Jun 2, 2010 280 SgtWookie: I think the I2C is just from the OP's solar charge controller to the master. My impression was a software Uart was going to be employed for the slaves, but I could be wrong. A standard RS232 transceiver can be had for$0.50-\$1.00.

I haven't tried, and not familiar with RS485/482, if that's what you are talking about.

#### SgtWookie

Joined Jul 17, 2007
22,210
I think that the PICAXE PIC08M is a PIC12F683 with a bootloader for the basic code.
The '683 doesn't have a UART. I was looking in the manual for the PICAXE, and the hi2cx commands are the only protocol that corresponds to what LostInSpace was talking about earlier; and those commands use the I2C protocol.

But now that I'm looking a bit closer, the 08 and 08M don't seem to support the I2C protocol, which is consistent with the PIC12F683 not having the hardware to support it. The 18X is apparently the lowest model PICAXE that supports I2C.

The 08M does support some serial communication commands, but our OP will have to do a fair amount of bit-banging to tell one slave from another.