[ create a new paste ] login | about

Link: http://codepad.org/qtYpZmIF    [ raw code | fork ]

Python, pasted on Oct 9:
'''
Python Script 00.08.00
    - by 7

'''

#32MHz Crystal Oscillator
Fosc=32e6 ## DONT MODIFY THIS

Prescaler=1 # [1,8,64,256]
PwmPeriod=1e-3  # 0.1msec
DutyCycleInPercent=.5 # 50%


###################################################
#### ---------------------------------------- #####
#### -- DON'T MODIFY ANYTHING BELOW THIS LINE #####
#### ---------------------------------------- #####
###################################################
'''
Configure and enable pulse-width modulation output in the AUX pin.
Requires a 5 byte configuration sequence.
Responds 0x01 after a complete sequence is received.
The PWM remains active after leaving binary bitbang mode! 
Equations to calculate the PWM frequency and period are in the PIC24F
output compare manual. Bit 0 and 1 of the first configuration byte
set the prescaler value. The Next two bytes set the duty cycle register,
high 8bits first. The final two bytes set the period register, high 8bits first.
'''
PrescalerList={1:0,8:1 ,64:2,256:3}
Tcy=2.0/Fosc
PRy=PwmPeriod/(Tcy*Prescaler)
PRy=PRy-1
OCR= PRy * DutyCycleInPercent


print "======================"
print "PwmPeriod: %.20f sec." % (PwmPeriod)
print "Tcy: %.20f sec." % (Tcy)
print "Prescaler: %d" % (int(Prescaler))
print "PR2: 0x%x = %d" % (int(PRy),int(PRy))
print "OCR: 0x%x = %d" % (int(OCR),int(OCR))
#####
print "5 Byte Setup:"
print "1st Byte: 0x%02x" % (int(PrescalerList[Prescaler]))
print "2nd Byte: 0x%02x" % ((int(OCR)>>8)&0xFF)
print "3rd Byte: 0x%02x" % (int(OCR)&0xFF)
print "4th Byte: 0x%02x" % ((int(PRy)>>8)&0xFF)
print "5th Byte: 0x%02x" % (int(PRy)&0xFF)


Create a new paste based on this one


Comments: