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.

DPWM (16bit would be best)

Status
Not open for further replies.

misiacik7

New Member
Hi there,

searching for a schematic of Digital PWM circuit, 12bit minimum, best would be 16bit. I want to drive the PWM analog, and later via PC (USB). I want to have 4 DPWM onboard. Want it cheap :)

Is there a way to do it, best would be to be able to connect more same boards together if I want to control it via PC, to have a control of them via single USB.
But this is sound of a future, for now I want to control it analog (Potenciometer without cycle limits (dont know how it is called :) )).

Is there a way to make it fade in (0% - 100%) when turned on in some seconds and to fade it out (100% - 0%) when it is turned off (with some 10s delay and then being fading out)?

Thanks in advice... :)
 

dougy83

Well-Known Member
Any reason for digital pwm? If you want to control it with analogue & digital, you may find it easier to make use of an analogue PWM circuit. It's straight-forward to drive with analogue; it can be controlled with digital also using a DAC.

You could alternatively use a microcontroller which may have all the DPWM you desire; the problem is that the PWM frequency will be very low for 16-bit resolution. With the analogue PWM there is not this problem (possibly problems with noise causing a reduction in bit resolution though).

As for fading (ramping) the control voltage, you can use an opamp configured as an integrator with the switching at the input.
 

blueroomelectronics

Well-Known Member
How did you determine you need a 16 bit PWM, what would need that sort of resolution and at what frequency? What do you consider cheap?
 

misiacik7

New Member
thanks for your advices so far, :)

I builded analog PWM with 555 timer so far with potenciometer, work well.

I want it to dim the leds... 4 / per board. I want the funcion I mentioned before (TURN on by fading in, delayed turn off by fading out).

I want it to via the potenciometer without positions, dont know how it is called. Please tell me. It is used in some stereos (is it digital pot.)

Cheap, means less then 10€ (15$) per board.

-12 bit (should be enough? 4095 steps for LED to get smooth dimming) (I am a bit megaloman if it comes to values :D)
-4 PWM outputs
-4 analog inputs (control)
-interface for digital com. for the future...
-ability to connect the same boards together and control them via one interface...

any idea :)
 
Last edited:

Gayan Soyza

Active Member
For fading LEDs 128 levels more than enough to make it smooth.If you need more go for 256 levels.You can make a software PWM without going for high end PICs.

If you cant do a software PWM then go for PIC18F4431.
 

Gayan Soyza

Active Member
For fading LEDs 128 levels more than enough to make it smooth.If you need more go for 256 levels.You can make a software PWM without going for high end PICs.

If you cant do a software PWM then go for PIC18F4431.
 

misiacik7

New Member
128 levels seems to be not eneugh for me, I will rather go more 4096 if it is not a problem... ( are you sure the 256 levels is enough to not see the flicker effect? )

what do you mean by software PWM? I am little bit amateur in this :))
 
Last edited:

mneary

New Member
256 levels is all you get in "DMX" theatrical lighting. As far as I know, there are no complaints. This is pretty much the world standard.
 

Sceadwian

Banned
A linear fading effect on a light source is going to give a very abrupt feeling to the turn on and off. To make a smooth appearing fading effect you have to use a sine table.
Software PWM means you use a timer loop and turn the I/O lines on and off yourself. This can give you as many PWM channels as you have I/O pins for and time to process. The flicker between stages seems to be noticeble with 256 steps, but only if you're looking right at it and the fade time is long. 128 should be good enough for general effect. If you want really nice smooth fluid changes to the lightning aim for 1024 or so, anything higher is probably overkill unless you need a completely unnoticeable slow change in brightness over a very long length of time.
 
Last edited:

Mr RB

Well-Known Member
You can generate the ON period just using TMR1 and an interrupt, this is easy enough to do on any pic and gives you 16bit resolution. You can generate 4 PWM signals by making one pulse after another.
 

misiacik7

New Member
I am not sure, but I want 4 separate channels...

OK, what is the general schematic for software PWM, what do I need (timer, ...). To get a better picture of it...

The potenciometer (wheel without positions I mentioned) what is it name?

If I want to control it that way, is it digital way, or analog?

thanks
 

Sceadwian

Banned
Mr RB, why are you talking about TMR1 misiacik7 hasn't mentioned micro controllers of any kind yet.
I builded analog PWM with 555 timer so far with potenciometer, work well.

I want it to dim the leds... 4 / per board. I want the funcion I mentioned before (TURN on by fading in, delayed turn off by fading out).

I want it to via the potenciometer without positions, dont know how it is called. Please tell me. It is used in some stereos (is it digital pot.)
Could you explain what you ment there a little better? It doesn't make much sense to me. Also if you can explain exactly what you want your device to do, your explanation so far is a little vague. If you've got a 555 connected to a pot and it works fine then do you want to automate this process so it fades in and out for you? And if so do you want a programmable delay?
It sounds like a micro controller would work well for you, one with 4 hardware PWM channels would be ideal but your demands aren't high so just about any general purpose micro controller would be able to do it as long as it was decently fast. You could program that software to do the fade in and fade out, and use push buttons for on and off to initiate the fading, no potentiometers needed.
 
Last edited:

Pommie

Well-Known Member
Most Helpful Member
Here's some code I wrote a while ago for a 16F88 that reads 2 analogue inputs and generates 2 PWMed outputs at a rate of 250Hz and 8 bits. It would be simple to extend it to 4 channels. You would probably have to drop the rate to 125Hz which should still be flicker free.

Code:
#include <system.h>
#include <boostc.h>
#pragma CLOCK_FREQ 8000000
#pragma DATA _CONFIG, _CP_OFF & _CCP1_RB0 & _DEBUG_ON 
        & _WRT_PROTECT_OFF & _CPD_OFF & _LVP_OFF & _BODEN_OFF 
        & _MCLR_ON & _PWRTE_OFF & _WDT_OFF & _INTRC_IO

int ReadADC(unsigned char);     //prototypes
unsigned char pwm1,pwm2;

void main(void){                //this is where it starts
unsigned char Led;              //define variables
    osccon=0x70;                //set internal oscillator to 8MHz
    cmcon=7;                    //turn comparators off
    ansel=0;                    //I/O is digital
    option_reg=08;              //prescaler set to WDT
    intcon=0xa0;                //enable timer 0 interrupts
    trisa=0b00111110;           //all LED pins output
    porta=0b10000001;           //two LEDs on. Bits 0&7 control LEDs
    while(1){                   //loop forever
        pwm1=ReadADC(1)>>2;     //VR1 controls LED 1
        pwm2=ReadADC(3)>>2;     //VR2 controls LED 2
    }                           //end of while loop
}	                            //end of main function

int ReadADC(unsigned char channel){
    if(channel<5)
        trisa|=(1<<channel);        //set the relevant
    else                            //tris bit to input
        trisb|=(1<<channel);
    ansel|=(1<<channel);            //and ensure it's analogue
    adcon0=0b01000001;              //Tosc/16 and ADC on
    adcon0|=(channel<<CHS0);        //select channel
    adcon1=0b11000000;              //right justify (and Tosc/16)
    delay_us(20);                   //wait for capacitor to charge
    adcon0.GO=1;                    //start conversion
    while(adcon0.GO);               //wait until completed
    return(adresh*256+adresl);      //return 10 bit value
}

void interrupt(void){
static unsigned char count;
	intcon.TMR0IF=0;                //clear interrupt flag
    tmr0=200;                       //next interrupt in 56 cycles
    if(count==pwm1)                 //if count reached pwm then
        trisa.7=1;                  //turn off LED
    if(count==pwm2)                 //same for
        trisa.0=1;                  //other LED
    if(++count==0){                 //increment count and if zero,
        trisa.0=0;                  //turn on
        trisa.7=0;                  //both LEDs
    }
}

It's in boostC. I think it works on a Junebug with a 16F88 instead of the 18F1320 but I'm not sure. It was a long time ago.

Edit, it is probably for a firefly board.

Mike.
 
Last edited:

Mr RB

Well-Known Member
Mr RB, why are you talking about TMR1 misiacik7 hasn't mentioned micro controllers of any kind yet.
...

I just made a logical leap. He said he wanted "digital PWM" "4 channels" with eventual "USB control from PC". It was not a big leap to deduce the OP was talking about a microcontroller.

Then someone mentioned doing it with a PIC in software PWM and then a PIC with dedicated PWM, then I mentioned an easy way to use a cheap PIC and get 4 PWM channels of 16bit resolution etc etc. :)
 

misiacik7

New Member
Thanks for all your replies... :)

Let me write it all again.

I want to have the option, to control the board via USB in the futere, now I will satisfy with the "manual" control. But still, I want to have the option for next extension. I want for now the rotary encoder if it acts like ( turn CW = VALUE +1, turn CCW = VALU -1).
It should behave this way:

1. TURN the Board on by pressing the button. ( DutyCycle = 0% in f.a. 4sec.)
2. After being turned on FADE IN ( DutyCycle: 0% -> 100%)
3. Second press of the button will cause turning off with dalay (wait for f.a. 15sec.)
4. After the dalay it should FADE OUT ( DutyCycle: 100% -> 0% in f.a. 4sec.)

Dont know which way is best to do this, if it is via analog PWM (555) or uProcessor. Have no experience with the uProc. but want to learn something. :) Have no problems with programming, seems to be similiar lang. to others I know... :)

Have on mind I want to make the board unversal, to have the option to extend and control it via USB.

f.a.:
1 USB -> 8 boards (with 4 separate channels)

The USB board should be on separate board with possibility to connect the PWM boards.

Thanks and hope that I am clear now :)
 

Sceadwian

Banned
For that kind of behavior you're really going to want to use a micro controller, doing it in discrete components would be possible, but complicated, and not very easy to interface to USB later.

Gets yourself a programmer and an mcu to work with. Just about any PIC or AVR can be connected to an external USB module to allow communication with a PC so you can worry about that at a later time. The PIC 18 line, and the AVR AtMega line are both popular micro controller lines you could chose from. There are others but those are the two most commonly supported here in the forums, and on the Internet in general.
 
Last edited:
Status
Not open for further replies.

EE World Online Articles

Loading
Top