The Godfather talking
You think I am funny guy huh?
Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
December 05, 2016, 03:26:41 03:26


Login with username, password and session length


Pages: [1]
Print
Author Topic: HPWM in PIC basic pro 2.50a  (Read 5781 times)
0 Members and 1 Guest are viewing this topic.
hell_pk
Guest
« on: March 27, 2008, 07:33:32 07:33 »

Hi!
Has someone done HPWM using new pic basic pro 2.50a and used all channels in 18F4431 or 18F2431 series.I read somewhere you can use HPWM command for all channels.Is this so.....
Logged
XZCV11
Guest
« Reply #1 on: March 27, 2008, 10:48:40 22:48 »

Why dont you just implement the PWM that is embedded into the microcontroller.  you just need to write to the CCPxCON and CCPRxL register.  I hope this helps
Logged
hell_pk
Guest
« Reply #2 on: March 28, 2008, 07:06:13 07:06 »

Actually i want to use power PWM module of microcontroller for brushless DC motor control.
Logged
eleckits
Junior Member
**
Offline Offline

Posts: 54

Thank You
-Given: 36
-Receive: 18


« Reply #3 on: March 28, 2008, 10:37:47 10:37 »

there is a difference between PWM and HPWM.

the PWM instruction can be used with any pin of the micro and the HPWM can you be used just for the pin which is build in hardware.
Logged
superkai
Inactive

 Muted
Offline Offline

Posts: 5

Thank You
-Given: 50
-Receive: 9


« Reply #4 on: March 31, 2008, 03:36:54 03:36 »

Try this just adap it!!
http://www.micro-examples.com/public/microex-navig/doc/097-pwm-calculator.html
Logged
spillaccio
Newbie
*
 Muted
Offline Offline

Posts: 8

Thank You
-Given: 42
-Receive: 7


« Reply #5 on: March 31, 2008, 11:52:19 23:52 »

Hello.
Try this sample code and see the math formulas for calculate your frequency.

'****************************************************************
'*  Name    : HPWM.BAS                                          *
'*  Author  : [select VIEW...EDITOR OPTIONS]                    *
'*  Notice  : Copyright (c) 2008 [select VIEW...EDITOR OPTIONS] *
'*          : All Rights Reserved                               *
'*  Date    : 24/03/2008                                        *
'*  Version : 1.0                                               *
'*  Notes   :                                                   *
'*          :                                                   *
'****************************************************************
'*                    TESTED ON PIC16F877A                      *
'****************************************************************
define osc 20
TRISA=%00000000
TRISB=%00000000
TRISC=%00000000
ADCON1=7
'****************************************************************
'Frequency ( f ) and period ( P ) are inversely proportional. f = 1/P, & P = 1/f.
'
'To calculate the value to be loaded into PR2:
'(20MHz / (4 * TMR2 prescale value * 38KHz)) - 1= PR2.
'
'We'll use a prescale value of 1 for timer2.
'
'4 * 1 * 250,000 = 1,000,000
'20,000,000 / 1,000,000 = 20
'20 - 1 = 19
'
'We'll load 19 into PR2, and accept the minimal error.
'******************************************************************
'******************************************************************
' I randomly chose a duty cycle of 50% for this application. To setup the duty cycle, there are two registers that need to be configured.
'
' CCPRL1  contains the eight (most significant bits), and CCP1CON <4:5> (CCP1CON bits 4 and 5) contain the two (least significant bits).
'Since we will only have a maximum of 6-bits resolution, we only need to load the CCPR1 register. CCP1CON bits 4 & 5 will be loaded with 0's.
'
'To figure the value to load into CCPRL1 for 38KHz @ 20MHz with a 50% duty cycle:
'
'(PR2 + 1) * TMR2 prescale * 50% Duty Cycle = value for CCPRL1, or
'(19 + 1) * 1 * 0.50 = 26 * 0.50 = 5
'******************************************************************
' IF YOU WANT TURN OFF THE PWM MODE SET CCP1CON = %00000000
'******************************************************************

PR2 = 19 ' Set PWM Period for exactly 250KHz
CCPR1L = 5 ' Set PWM Duty-Cycle APPROX. to 50%  "IF NECESSARY CHANGE VALUE TO 10"
CCP1CON = %00001100 ' Mode select = PWM
T2CON = %00000100 ' Timer2 ON + 1:1 prescale ratio
TRISC.2 = 0 ' CCP1 to Output

MAIN:
'YOUR PROGRAM"
GoTo MAIN

Spillaccio
« Last Edit: March 31, 2008, 11:55:33 23:55 by spillaccio » Logged
nileshhande
Junior Member
**
Offline Offline

Posts: 70

Thank You
-Given: 22
-Receive: 5


« Reply #6 on: October 19, 2008, 12:50:24 12:50 »

Hi, Could you please explain if i use 16f877a with 4mhz crystal then what all changes required in this code?
Thanks.
Logged
Pages: [1]
Print
Jump to:  


DISCLAIMER
WE DONT HOST ANY ILLEGAL FILES ON THE SERVER
USE CONTACT US TO REPORT ILLEGAL FILES
ADMINISTRATORS CANNOT BE HELD RESPONSIBLE FOR USERS POSTS AND LINKS

... Copyright 2003-2999 Sonsivri.to ...
Powered by SMF 1.1.18 | SMF © 2006-2009, Simple Machines LLC | HarzeM Dilber MC