I would love to see some small Pulse Width Modulators in stock, either as kits, or pre-assembled. Perhaps a low freq and a high freq, with adjustable duty cycle. The smaller the better!
You do realize that even a good portion of the low end PICs have built in hardware PWM modules with a price comparable to a dedicated IC except with much greater versatility.
-Bill
I was hoping for something that works straight out of the box, but this being a community heavy on DIY, I suppose I should just ask for a tutorial? Perhaps there is one already in existence, but I haven’t stumbled across it yet?
Thanks!
Microchip has several relevant app notes and software examples. Here is a simple program of mine that varies the brightness of an LED:
;16F88 PWM test program
;pwm output on RB0/CCP1 pin (pin 6)
;connect an LED and 330R resistor between pin 6 and Gnd
#include "p16f88.inc"
list p=16f88, r=dec
#define INIT_COUNT 100
cblock 0x20
flags
Loop1
Loop2
endc
org 0
goto start
org 4
bcf INTCON,TMR0IF ;clear Timer0 interrupt flag
movlw INIT_COUNT ;initialise timer count value
movwf TMR0
bsf flags,0
retfie
start:
call Initialisation
loop:
incf CCPR1L
call dly
goto loop
Initialisation:
banksel OPTION_REG
movlw b'00000111' ;prescaler 1/256
movwf OPTION_REG ;giving 8 Mz/256 = 28800 Hz (period = 35 us)
banksel TMR0
movlw INIT_COUNT ;initialise timer count value
movwf TMR0
banksel INTCON
bsf INTCON,TMR0IE ;enable Timer0 interrupt
bsf INTCON,GIE ;enable global interrupt
banksel PORTB
clrf PORTB ; clearing output
; data latches
banksel ANSEL
movlw 0x00 ; configure all pins
movwf ANSEL ; as digital inputs
banksel TRISB
bcf TRISB,0 ; PWM output on pin 6
banksel PR2
movlw b'11111001' ; set PWM period
movwf PR2
banksel T2CON
movlw b'00000111' ; TMR2 = on, prescale = 1/16
movwf T2CON
banksel CCPR1L
movlw b'01111100' ; set bits <9..2>
movwf CCPR1L
banksel CCP1CON
movlw b'00111100' ; enable PWM and set bits <1:0>
movwf CCP1CON
return
dly:
MOVLW 0x30
MOVWF Loop1
Outer:
MOVLW 0x55
MOVWF Loop2
Inner:
NOP
NOP
DECFSZ Loop2,F
GOTO Inner ; Inner loop = 5 usec.
DECFSZ Loop1,F
GOTO Outer
RETURN
end
Leon
I can’t think of something much simpler than a 555. Is there a reason you don’t want to use that?
I read up on the astable 555, and found the equation for calculating the values, but I suppose I’m not really comfortable with working through the circuits on my own just yet. I enjoy sparkfun products because the hard work of general board development is already done.
Anyway, thanks for the suggestions! I suppose I just need to suck it up and go over circuit theory again.
Cheers!
for the 555, use a calculator like this one - http://ourworld.compuserve.com/homepage … en/555.htm
It’s pretty much cook book.
eh? works for me.