PDA

View Full Version : setting up HPWM



sunny
- 20th October 2006, 02:36
Hi ,

I want know because using the Picbasic Pro function HPWM the max frequency at any oscillator speed is 32.767 kHz, but and using manual register setup, using 20 MHz Xtal can get 2 MHz.

manual register setup for 1 mhz PWM PIC 16F873

PR2 = 4
T2CON = %0000100
CCPR1L = 2
CCP1CON = %00011100

Freq out 1.0 MHz 50 % Duty Cycle


interesting link :http://www.micro-examples.com/public/microex-navig/doc/097-pwm-calculator.html

regards

sunny

mister_e
- 20th October 2006, 03:11
You can't have 2MHZ, it's going to be 1.66666MHZ or 2.5MHZ for that crystal speed

For 1.66666MHZ and a huge 5 bit resolution
PR2 = 4
T2CON = %00000100
CCPR1L =1
CCP1CON = %00101100


For 2.5MHZ and 5 bit resolution
PR2 = 1
T2CON = %00000100
CCPR1L =1
CCP1CON = %00001100

don't forget to set the TRISx bit.

If you really need 2MHZ, 40MHZ or 48MHZ crystal will work.

sunny
- 20th October 2006, 03:35
Hi Steve,


May be I don't explain me very well ( sorry about my English ! )

Im concerned why using PBP HPWM function the max freq be 32767 Hz.

DEFINE CCP1_REG PORTC 'Hpwm 1 pin port
DEFINE CCP1_BIT 2 'Hpwm 1 pin bit
DEFINE HPWM2_TIMER 1 'Hpwm 2 timer select

HPWM 1,127,32767 ' Send a 50% duty cycle PWM signal at 32767 Hz

( PBP MANUAL : The highest frequency at any oscillator speed is 32767Hz )


Settings manually the registers and don't use PBP HPWM function i can get too much frequency range to the ouput of PWM .


Best Regards

Sunny

mister_e
- 20th October 2006, 13:28
Ok i try again, is the question is Why the HPWM can't provide more than 32.767 KHZ?

Don't worry about your english... i know what you mean and how hard it is.. i'm french.. but Canadian (cool down Alain :D )

sunny
- 20th October 2006, 19:35
Hi Steve ,


( Ok i try again, is the question is Why the HPWM can't provide more than 32.767 KHZ? )


Yes I want know why !



Regards

Sunny


P.S :

I'm be concerned about some statements used in a code example that you early write in another post.

(Fullfilling lookup tables )

@CSize=CODE_SIZE ; get the PIC Codespace size

LookupStart=(CSize*1024)-512
' get the Lookup first address
' As i used the bootloader i just move
' the adress to a x place

mister_e
- 20th October 2006, 21:37
for the frequency limitation i guess it's an assembler maths limitation. it's hard to fit millions or 1/milions in a 16bit maths routine and/or in a Word size variable :)

Look in your datahseet to know how to calculate the PR2 value and search for HPWM in PBPPIC14.LIB file to know how the calc are done.



I'm be concerned about some statements used in a code example that you early write in another post.
What do you want to know?

sunny
- 21st October 2006, 02:02
Hi Steve ,


Thanks you for answer my question !

My doubts about HPWM be cleared now.

I learned about PWM and how to setting up registers.

I don't be working in a project , only want to learn from the forum , thanks to you and all the members this be possible.

Thanks a lot !

Another question related to " Fullfilling lookup tables " be the following :


1 ) From where you get this statement @CSize=CODE_SIZE ?

2) How work them ?

3 ) You use in this code (CSize*1024)-512 can explain me about it ?

Sorry may be too many question !


Thanks in advance

Sunny

mister_e
- 21st October 2006, 19:46
1 ) From where you get this statement @CSize=CODE_SIZE ?
From my head :D

CODE_SIZE
this is a PBP internal variable that return the code size of the PIC you use. If i open the 16F877.BAS file in the PBP directory and i scroll a little bit in, i will find the following...


DEFINE CODE_SIZE 8

YEAH! 16F877 is a 8K size

@CSize=CODE_SIZE
It define an assembler variable

Later i used
CSize con EXT

This allow to have this value available in the PBP code

3 ) You use in this code (CSize*1024)-512 can explain me about it ?
8K=8*1024 Bytes
the -512 is because i used the Bootloader. The bootloader program is usually located at the end of the codespace. so the first Table address is located 512 bytes before the codespace end.

sunny
- 22nd October 2006, 01:36
Hi Steve,

Great !!


Thanks a lot for all the explanation !!

You are right :

( There's no problem. Only learning opportunities. )

Regards

Sunny