View Full Version : generate 38 KHz help
iw2fvo
- 4th May 2017, 21:43
Good day to all in this forum,
I have a pic18f252 witha a 10 Mhz XTAL an d a X4 PLL multiplier that gives 40 MHz clock speed.
I need to generate 38 KHZ to control some IR devices.
How to do that please ?
Thanks
regards,
Ambrogio
mark_s
- 4th May 2017, 22:15
One way is to use HPWM, here is an example.
http://www.picbasic.co.uk/forum/showthread.php?t=20921
iw2fvo
- 8th May 2017, 19:01
Thanks a lot for the kind assistance: HPWM works very well.
I also follow the indicated links and I found this code:
TRISC.2 = 0 ' CCP1 (PortC.2 = Output)
PR2 = 25 ' Set PWM Period for approximately 38KHz
CCPR1L = 13 ' Set PWM Duty-Cycle to 50%
CCP1CON = %00001100 ' Mode select = PWM
T2CON = %00000100 ' Timer2 ON + 1:1 prescale
Question: Why I do have a frequency equivalent to 10 times 38 KHz ( about 384 KHz ! ) ?
I did declare osc= 40 Mhz too.
Thanks for any clarification,
regards,
Ambrogio
mark_s
- 9th May 2017, 00:10
I believe the example was for 4 or 8mhz oscillator. You need to adjust PR2 and CCCPR1L for your 40Mhz clock.
Try this calculator
http://www.micro-examples.com/public/microex-navig/doc/097-pwm-calculator.html
iw2fvo
- 9th May 2017, 14:05
thanks Mark_s,
the suggeted calculator is very OK !
Bye,
Ambro
Powered by vBulletin® Version 4.1.7 Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.