PDA

View Full Version : HPWM down



lerameur
- 9th January 2007, 20:41
I am attempting to control my motor using the HPWM. The code works, but the header has a problem .

I used a header from a post I found here,it works, but I would liek to know what is wrong with mine

This do not work:
INCLUDE "modedefs.bas"
DEFINE OSC 20 'use external 20mhz crystal
PAUSE 300 ' start-up delay
DEFINE CCP1_REG PORTB 'Hpwm 1 pin port, RIGHT
DEFINE CCP1_BIT 3 'Hpwm 1 pin bit

TRISA = %11111111 ' Set PORTA to all input
TRISB = %00000000
loop:
HPWM 1,127,1000

Goto loop 'Do it forever
end


This code works:
@ DEVICE MCLR_ON, INTRC_OSC, WDT_ON, LVP_OFF, BOD_OFF, PWRT_ON, PROTECT_OFF, CCPMX_ON
OSCCON=$60 ' use internal 4MHZ osc
PAUSE 300 ' start-up delay
DEFINE CCP1_REG PORTB 'Hpwm 1 pin port, RIGHT
DEFINE CCP1_BIT 3 'Hpwm 1 pin bit

TRISA = %11111111 ' Set PORTA to all input
TRISB = %00000000
loop:
HPWM 1,127,1000

Goto loop 'Do it forever
end

As soon as i turn off the internal oscillation and put in a 20Mhz crystal, it does not work

BigWumpus
- 9th January 2007, 22:41
In your first program you forgot the "@ device"-statement. This statement is neccessary for every program! How should the PIC knows to initialize his oszillator ?
And use the "DEFINE OSC"-statement !

mister_e
- 9th January 2007, 23:23
Yes and no, it goes much than this... using 20MHz, you can't produce a 1KHZ frequency. The lowest would be around 1.221 KHz...

It's all explain in the PBP manual OR showned in my PicMultiCalc.
<img SRC="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1318&stc=1&d=1168384977">

lerameur
- 9th January 2007, 23:48
like i said I tried that:
Here is the code, it does not work, it always stays on high

@ DEVICE PIC16F88, MCLR_ON, HS_OSC, WDT_ON, LVP_OFF, BOD_OFF, PWRT_ON, PROTECT_OFF, CCPMX_ON

INCLUDE "modedefs.bas"
DEFINE OSC 20 'use external 20mhz crystal

PAUSE 100 ' start-up delay

DEFINE CCP1_REG PORTB 'Hpwm 1 pin port, RIGHT
DEFINE CCP1_BIT 3 'Hpwm 1 pin bit

TRISA = %11111111 ' Set PORTA to all input
TRISB = %00000000

loop:
PORTB.4=1 'Enable B+ Both motors forward
PORTB.5=0 'Enable B-
PortB.6=1 'Enable A+
PortB.7=0 'Enable A-
HPWM 1,127,2000 'enable pin 13 Now for the speed of each motor
pause 5500
HPWM 1,210,2000
pause 5500

Goto loop 'Do it forever
end

mister_e
- 9th January 2007, 23:50
HPWM 1,127,1300 'enable pin 13 Now for the speed of each motor
pause 5500
HPWM 1,210,1300

about now?

EDIT: it's working here...

lerameur
- 10th January 2007, 00:06
I decided to put it at 5000
HPWM 1,127,5000 'enable pin 13 Now for the speed of each motor
pause 5500
HPWM 1,210,5000
pause 5500
and it works


thanks guys