PDA

View Full Version : HPWM confusion



lerameur
- 3rd November 2006, 02:10
Hi,

I am learning the HPWM command.. mainly because I need a PWM for my motors. But I was wandering what the command ccp1 does in the Pic16f876a chip does. At first I thought I needed it, but then i saw that the Pic16F84 dont have one and it is possible to have PWM, Actually I guess its a question of, what pin is turning on and off at a specific duty cycle. So what is the PWM mode in the pic16F876a with the CCP0, CCP1, What does it give more then the 16F84 chip.

thanks

ken

mat janssen
- 3rd November 2006, 08:15
The PWM command in PBP is a software pwm generator. When this command is running nothing else is workin until the pwm genarator is ready, because you give the dutycycle and the number of cycles of this pwm to the genarator.
When the cycles are done then the next command is working.
The HPWM command is a command what goes directly to the hardware buils in pwm generator. When it is started is will work until you give a command to stop or to give it another dutycycle. Meanwhile your programm is doing then next instructions without concirning about the pwmgenerator.

sayzer
- 3rd November 2006, 08:56
For CCP1, I also would like to ask a question in addition to lerameur's, as I am also having new experiences with PWM.

1. When setting PR2 and CCP1, say we set CCP1 for a fixed number. Then we play with PR2 to get the correct freq (in brief I say it this way).

2. But, when I set PR2=255 fixed, and then play with CCP1, I also get the same freqs as in number 1 above.


So what should be my question here, I am not sure.


-----------------------

Melanie
- 3rd November 2006, 09:33
>> But I was wandering what the command ccp1 does in the Pic16f876a chip does.

CCP1 is NOT a command, but a REGISTER within your PIC.

To discover what it does, download and read the Datasheet for your PIC16F876A. A really good place to start is section 8 - Capture/Compare/PWM Modules.

sayzer
- 3rd November 2006, 11:16
Welcome back Melanie!



----------------------------------

lerameur
- 3rd November 2006, 11:47
So grossely, I am doing a line following robot, if I use PWM, then the sensors are not working. Also, I only have two channel to use PWM, so only two motors can use HPWM on one chip. right?

k

mat janssen
- 3rd November 2006, 11:56
Thats wright.
A 16F87(3)6 should do it. It has 2 Hpwm outputs.

lerameur
- 4th November 2006, 21:17
HI,

I am using an H-bridge L293. It seems that there are thre wires per motor for control. 1 for neg. , 1 for pos. and one for the HPWM. The PWM is put on the CCP1, while the other do not matter, as long as they are configured as 1 or 0 right ? well thats what I concluded from what I read. Is there any reason why this code would not work ? I am not getting any output

if right > left Then
temp =right-left
temp= temp * 254
temp= temp/right
PORTC.4=0
PORTC.5=1
HPWM 1,255-temp,1000
HPWM 2,255,1000

Else
temp =left-right
temp= temp * 254
temp= temp/left
PORTC.4=1
PORTC.5=0
HPWM 2,255-temp,1000
HPWM 1,255,1000
Endif

lerameur
- 4th November 2006, 21:35
To be more precise, the circuit seems to wok without the motor connected. when i conencted the motor, then the LCD screens shows very low numbers, and the motor might turn just for 1-2 seconds, otherwise it makes a noise, I guess thats my 2000hz
Just one time the motor turned on and changes direction 3 times very quickly.

Should my power supply for the L293 be different then for the pic ?

k

lerameur
- 4th November 2006, 22:48
last code still not working
Again i hear a buzz, and sometime the motor turns a little.
Also on the oscilloscope, sometime he output is sitting at zero, or when its oscillating, it looks like its going from -4 to 1volt

if right > left Then
temp =right-left
temp= temp * 254
temp= temp/right
PORTC.4=0
PORTC.5=1
HPWM 1,255-temp,2000
HPWM 2,255,2000
Endif

if left >= right then
temp =left-right
temp= temp * 254
temp= temp/left
PORTC.6=0
PORTC.7=1
HPWM 2,255-temp,2000
HPWM 1,255,2000
Endif

sayzer
- 5th November 2006, 08:32
lerameur,

Why don't you create an excel sheet and see all numbers?

Have all possible right and left values in a row, and do the formula, put the result in another row.

Then you can see how the numbers behave, from a possible minimum value to a possible maximum value.


-------------

mister_e
- 5th November 2006, 09:42
Should my power supply for the L293 be different then for the pic ?


It's usualy a good pratice to split your PSU lines. You could use one regulator/line.

Also, when dealing with POWER, you should split your GND lines (analog, Digital, PowerDevices) then tie them at them at a single point.

It's also good practice to isolate POWER from Logic. OPTO couplers come handy in those case.

Be sure ALL psu line are well filtered and noise free.

Another things... be sure you Motor don't need much current than regulator can give.



last code still not working
Again i hear a buzz, and sometime the motor turns a little.
Also on the oscilloscope, sometime he output is sitting at zero, or when its oscillating, it looks like its going from -4 to 1volt


O.K, could you provide more details, wich motor model you use and post your schematic here.

Personnally i hate guessing. I'm sure we could find the solution faster if you posted the whole thing on your first post.

Please for the next(s) time(s) give us all you have. A schematic is often a MUST. If you have a board layout too.

lerameur
- 5th November 2006, 10:09
I am going out of town for a few days, I will post again when I come back

k