|
|
View previous topic :: View next topic |
Author |
Message |
ymoona
Joined: 20 Mar 2005 Posts: 32 Location: Heiloo, the Netherlands
|
16F690 pulse steering, 4 pin PWM |
Posted: Mon Jun 18, 2007 8:32 am |
|
|
Hi,
I´m trying to get my dual motor driver to work. I found on the microchip site that the 16f690 has 4 PWM channels.
How do I get them to work? So far I got only RC2 ( PIN 14) to generate a PWM signal. How does the pulse steering work?
I´m using an l298. I connected C2, C3, C4, C5 to input 1 till 4 of the dual motor driver.
How do I get controll of the 4 pwm channels? _________________ checkout my site: www.ymoona.com/wiki |
|
|
Ttelmah Guest
|
|
Posted: Mon Jun 18, 2007 9:28 am |
|
|
MicroChip, seem determined to annoy people with their nomenclature on the PWMs....
The 690, only has _one_ PWM. It has options to route it's output to four pins, in different drive modes (for half bridge, and full bridge drive of a single motor), but it is not capable of giving you two distinct PWM trains, to drive two motors. :(
Best Wishes |
|
|
ymoona
Joined: 20 Mar 2005 Posts: 32 Location: Heiloo, the Netherlands
|
|
Posted: Mon Jun 18, 2007 9:33 am |
|
|
Ttelmah wrote: | MicroChip, seem determined to annoy people with their nomenclature on the PWMs....
The 690, only has _one_ PWM. It has options to route it's output to four pins, in different drive modes (for half bridge, and full bridge drive of a single motor), but it is not capable of giving you two distinct PWM trains, to drive two motors. :(
Best Wishes |
Thanks, so it has only one PWM. But it can be routed to one ore _multiple_ pins. How do I set this up? _________________ checkout my site: www.ymoona.com/wiki |
|
|
Ttelmah Guest
|
|
Posted: Mon Jun 18, 2007 10:19 am |
|
|
OK.
In the .h file for the processor, there should be defines for the pwm setup, giving:
Code: |
#define CCP_PWM_H_H 0x0c
#define CCP_PWM_H_L 0x0d
#define CCP_PWM_L_H 0x0e
#define CCP_PWM_L_L 0x0f
#define CCP_PWM_FULL_BRIDGE 0x40
#define CCP_PWM_FULL_BRIDGE_REV 0xC0
#define CCP_PWM_HALF_BRIDGE 0x80
#define CCP_PULSE_STEERING_A 0x01000000
#define CCP_PULSE_STEERING_B 0x02000000
#define CCP_PULSE_STEERING_C 0x04000000
#define CCP_PULSE_STEERING_D 0x08000000
|
You 'OR' these with the CCP_PWM setup, to give the required behaviours. You can feed the single PWM, to any of the four output pins with the last four commands, or to multiple pins, in the half bridge/full bridge patterns with the middle three commands. The top four, control the output polarity.
Best Wishes |
|
|
ymoona
Joined: 20 Mar 2005 Posts: 32 Location: Heiloo, the Netherlands
|
|
Posted: Mon Jun 18, 2007 2:09 pm |
|
|
I found the these constands in the header file for my PIC.
But I only get pin A to work, this is the code I used:
Code: |
setup_ccp1(CCP_PWM);
set_pwm1_duty(100);
while(1){
output_high( led );
setup_ccp1( CCP_PULSE_STEERING_A | CCP_PWM_L_H );
delay_ms(1000);
setup_ccp1( CCP_PULSE_STEERING_A |CCP_PWM_L_H);
delay_ms(1000);
setup_ccp1( CCP_PULSE_STEERING_A |CCP_PWM_H_L);
delay_ms(1000);
setup_ccp1( CCP_PULSE_STEERING_A | CCP_PWM_L_L);
output_low( led );
setup_ccp1( CCP_PULSE_STEERING_B | CCP_PWM_L_H );
delay_ms(1000);
setup_ccp1( CCP_PULSE_STEERING_B |CCP_PWM_L_H);
delay_ms(1000);
setup_ccp1( CCP_PULSE_STEERING_B |CCP_PWM_H_L);
delay_ms(1000);
setup_ccp1( CCP_PULSE_STEERING_B | CCP_PWM_L_L);
delay_ms(1000);
output_high( led );
setup_ccp1( CCP_PULSE_STEERING_C | CCP_PWM_L_H );
delay_ms(1000);
setup_ccp1( CCP_PULSE_STEERING_C |CCP_PWM_L_H);
delay_ms(1000);
setup_ccp1( CCP_PULSE_STEERING_C |CCP_PWM_H_L);
delay_ms(1000);
setup_ccp1( CCP_PULSE_STEERING_C | CCP_PWM_L_L);
delay_ms(1000);
output_low( led );
setup_ccp1( CCP_PULSE_STEERING_D | CCP_PWM_L_H );
delay_ms(1000);
setup_ccp1( CCP_PULSE_STEERING_D |CCP_PWM_L_H);
delay_ms(1000);
setup_ccp1( CCP_PULSE_STEERING_D |CCP_PWM_H_L);
delay_ms(1000);
setup_ccp1( CCP_PULSE_STEERING_D | CCP_PWM_L_L);
delay_ms(1000);
output_high( led );
delay_ms(500);
}
}
|
What is going wrong? Only PinA is showing activity, the other pins are completely dead!
I´m not sure what the following defines mean, how do they help me
Code: |
#define CCP_PWM_H_H 0x0c
#define CCP_PWM_H_L 0x0d
#define CCP_PWM_L_H 0x0e
#define CCP_PWM_L_L 0x0f
#define CCP_PWM_FULL_BRIDGE 0x40
#define CCP_PWM_FULL_BRIDGE_REV 0xC0
#define CCP_PWM_HALF_BRIDGE 0x80
|
I want 1 PWM signal splitted over ONE or MULTIPLE pins, How should I do this? _________________ checkout my site: www.ymoona.com/wiki |
|
|
Ttelmah Guest
|
|
Posted: Mon Jun 18, 2007 3:17 pm |
|
|
Look at the data sheet.
The defines exactly correspond to the configuration bits in the registers for the PWM. So:
1100 = PWM mode; P1A, P1C active-high; P1B, P1D active-high
1101 = PWM mode; P1A, P1C active-high; P1B, P1D active-low
1110 = PWM mode; P1A, P1C active-low; P1B, P1D active-high
1111 = PWM mode; P1A, P1C active-low; P1B, P1D active-low
Correspond to the first four defines.
Then read the maual for SETUP_CCP1, and realise that for the ECCP, you need _two_ parameters...
setup_ccp1(CCP_PWM, CCP_PWM_H_H |CCP_PULSE_STEERING_B);
Beware that the steering only works in single output mode.
Best Wishes |
|
|
ymoona
Joined: 20 Mar 2005 Posts: 32 Location: Heiloo, the Netherlands
|
|
Posted: Tue Jun 19, 2007 11:21 am |
|
|
Ttelmah wrote: | Look at the data sheet.
The defines exactly correspond to the configuration bits in the registers for the PWM. So:
1100 = PWM mode; P1A, P1C active-high; P1B, P1D active-high
1101 = PWM mode; P1A, P1C active-high; P1B, P1D active-low
1110 = PWM mode; P1A, P1C active-low; P1B, P1D active-high
1111 = PWM mode; P1A, P1C active-low; P1B, P1D active-low
Correspond to the first four defines.
Then read the maual for SETUP_CCP1, and realise that for the ECCP, you need _two_ parameters...
setup_ccp1(CCP_PWM, CCP_PWM_H_H |CCP_PULSE_STEERING_B);
Beware that the steering only works in single output mode.
Best Wishes |
But I dont want single output, I want multiple output.
setup_ccp1(CCP_PWM, CCP_PWM_H_H |CCP_PULSE_STEERING_B); doesnt work. I get an compiler error: Expecting a close paren. What is going wrong here? _________________ checkout my site: www.ymoona.com/wiki |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Jun 19, 2007 12:34 pm |
|
|
Post your compiler version. |
|
|
ymoona
Joined: 20 Mar 2005 Posts: 32 Location: Heiloo, the Netherlands
|
|
Posted: Tue Jun 19, 2007 2:19 pm |
|
|
PCM programmer wrote: | Post your compiler version. |
IDE 4.013
PCM 4.013
PCM 4.013
PCH 4.013 _________________ checkout my site: www.ymoona.com/wiki |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Jun 19, 2007 3:42 pm |
|
|
The closest I have to your version is PCM vs. 4.014. I was able to
make it work with that version. See the test program shown below.
The key point is that you have to put in code to make the additional PWM
pins into output pins. The compiler doesn't do it for you automatically.
This is shown in the code.
Code: |
#include <16F690.h>
#fuses INTRC_IO, NOWDT, NOPROTECT, BROWNOUT, PUT, NOMCLR
#use delay(clock=8000000)
#define P1A PIN_C5
#define P1B PIN_C4
#define P1C PIN_C3
#define P1D PIN_C2
//===========================================
void main()
{
setup_timer_2(T2_DIV_BY_16, 124, 1); // 1000 Hz
set_pwm1_duty(31); // 25% duty cycle
// Enable PWM pins P1B, P1C, and P1D for output.
// Note: P1A is done by the compiler.
output_low(P1B);
output_low(P1C);
output_low(P1D);
// Steer the PWM output to all four P1x pins.
setup_ccp1(CCP_PWM_H_H | CCP_PULSE_STEERING_A
| CCP_PULSE_STEERING_B
| CCP_PULSE_STEERING_C
| CCP_PULSE_STEERING_D );
while(1);
} |
|
|
|
ymoona
Joined: 20 Mar 2005 Posts: 32 Location: Heiloo, the Netherlands
|
|
Posted: Sun Jun 24, 2007 12:14 pm |
|
|
PCM programmer wrote: | The closest I have to your version is PCM vs. 4.014. I was able to
make it work with that version. See the test program shown below.
The key point is that you have to put in code to make the additional PWM
pins into output pins. The compiler doesn't do it for you automatically.
This is shown in the code.
Code: |
#include <16F690.h>
#fuses INTRC_IO, NOWDT, NOPROTECT, BROWNOUT, PUT, NOMCLR
#use delay(clock=8000000)
#define P1A PIN_C5
#define P1B PIN_C4
#define P1C PIN_C3
#define P1D PIN_C2
//===========================================
void main()
{
setup_timer_2(T2_DIV_BY_16, 124, 1); // 1000 Hz
set_pwm1_duty(31); // 25% duty cycle
// Enable PWM pins P1B, P1C, and P1D for output.
// Note: P1A is done by the compiler.
output_low(P1B);
output_low(P1C);
output_low(P1D);
// Steer the PWM output to all four P1x pins.
setup_ccp1(CCP_PWM_H_H | CCP_PULSE_STEERING_A
| CCP_PULSE_STEERING_B
| CCP_PULSE_STEERING_C
| CCP_PULSE_STEERING_D );
while(1);
} |
|
thanks!! that did the trick. But is seems to have a problem with the while loop Ive wrote.
Code: |
while(1){
setup_ccp1(CCP_PWM_H_H | CCP_PULSE_STEERING_A );
set_pwm1_duty(31); // 25% duty cycle
output_high( led );
delay_ms(2000);
// left wheels backward, right wheels not moving
setup_ccp1(CCP_PWM_H_H | CCP_PULSE_STEERING_B );
set_pwm1_duty(31); // 25% duty cycle
output_low( led );
delay_ms(2000);
}
|
The problem is that the first time this loop is passed. Every thing is ok. but the second time the left wheels only steer backwards, changing from 100% to 25% duty. _________________ checkout my site: www.ymoona.com/wiki |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Jun 24, 2007 12:28 pm |
|
|
Post a test program similiar to the one that I did, except that it has your
loop code in it. Make sure the program is compilable. For example,
the LED pin must be defined.
Also, you have the P1A, P1B, etc. outputs attached to wheel motors.
Post a list of which output pin drives which motor. i.e., P1A is the left
motor, etc. In other words, post a full explanation. |
|
|
ymoona
Joined: 20 Mar 2005 Posts: 32 Location: Heiloo, the Netherlands
|
|
Posted: Sun Jun 24, 2007 1:34 pm |
|
|
this is the code I currently use:
Code: |
#include <16F690.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES INTRC_IO //Internal RC Osc, no CLKOUT
#FUSES NOPROTECT //Code not protected from reading
#FUSES BROWNOUT //Reset when brownout detected
#FUSES MCLR //Master Clear pin enabled
#FUSES NOCPD //No EE protection
#FUSES NOPUT //No Power Up Timer
#FUSES IESO //Internal External Switch Over mode enabled
#FUSES FCMEN //Fail-safe clock monitor enabled
#use delay(clock=8000000)
#use i2c(Slave,Slow,sda=PIN_C4,scl=PIN_C3,force_hw,address=0x00110011)
/*
Pin defines
*/
#define led PIN_A5
#define driver_a PIN_C0
#define driver_b PIN_C1
/*
Variables
*/
/*
Function prototypes
*/
void set_drivers( int1 value );
#int_SSP // i2c activty
SSP_isr()
{
return;
}
void main(){
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
//setup_timer_2(T2_DIV_BY_1,255,1);
setup_timer_2(T2_DIV_BY_16, 124, 1); // 1000 Hz
setup_comparator(NC_NC_NC_NC);
//enable_interrupts(INT_SSP);
//enable_interrupts(GLOBAL);
setup_oscillator(OSC_8MHZ);
set_drivers( true );
set_pwm1_duty(31); // 25% duty cycle
output_low(PIN_C5);
output_low(PIN_C4);
output_low(PIN_C3);
output_low(PIN_C2);
output_high( led );
delay_ms(500);
output_low( led );
delay_ms(500);
output_high( led );
delay_ms(500);
output_low( led );
delay_ms(500);
while(1){
// left wheel foreward, right wheels not moving
setup_ccp1(CCP_PWM_H_H | CCP_PULSE_STEERING_A );
set_pwm1_duty(31); // 25% duty cycle
output_high( led );
delay_ms(1000);
// left wheels backward, right wheels not moving
setup_ccp1(CCP_PWM_H_H | CCP_PULSE_STEERING_B );
set_pwm1_duty(31); // 25% duty cycle
output_low( led );
delay_ms(1000);
}
}
/*
Funtion boddies
*/
void set_drivers( values ){
if( values ){
output_high( driver_a );
output_high( driver_b );
}
else{
output_low( driver_a );
output_low( driver_b );
}
}
|
for hardware I use a l298(a dual H-bridge)
l298 input1 -> RC2 D
l298 input2 -> RC3 C
l298 input3 -> RC4 B
l298 input4 -> RC5 A
the driver enable pins are also connected.
note: when I drive de motors without PWM the dual H-Bridge setup works just fine. Tested with the following code:
Code: |
while(1){
output_high( PIN_A5 );
// drive motor A
output_low( PIN_C3 );
output_high( PIN_C2 );
// drive motor B
output_low( PIN_C4 );
output_high( PIN_C5 );
delay_ms(5000);
output_low( PIN_A5 );
// driver motor A
output_low( PIN_C2 );
output_high( PIN_C3 );
// driver motor Ab output_low( PIN_C5 );
output_high( PIN_C4 );
delay_ms(5000);
|
_________________ checkout my site: www.ymoona.com/wiki |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Jun 24, 2007 1:43 pm |
|
|
Quote: |
#use i2c(Slave,Slow,sda=PIN_C4,scl=PIN_C3,force_hw,address=0x00110011)
output_low(PIN_C5);
output_low(PIN_C4);
output_low(PIN_C3);
output_low(PIN_C2); |
You're using software i2c on the same pins that you're using for your motor driver.
The 16F690 does have hardware i2c pins, but they're on pins B4 and B6,
not C4 and C3. |
|
|
ymoona
Joined: 20 Mar 2005 Posts: 32 Location: Heiloo, the Netherlands
|
|
Posted: Sun Jun 24, 2007 1:55 pm |
|
|
PCM programmer wrote: | Quote: |
#use i2c(Slave,Slow,sda=PIN_C4,scl=PIN_C3,force_hw,address=0x00110011)
output_low(PIN_C5);
output_low(PIN_C4);
output_low(PIN_C3);
output_low(PIN_C2); |
You're using software i2c on the same pins that you're using for your motor driver.
The 16F690 does have hardware i2c pins, but they're on pins B4 and B6,
not C4 and C3. |
thanks! stupid me! but it not the solution for my problem :(
any other ideas? this is the current software
Code: |
#include <16F690.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES INTRC_IO //Internal RC Osc, no CLKOUT
#FUSES NOPROTECT //Code not protected from reading
#FUSES BROWNOUT //Reset when brownout detected
#FUSES MCLR //Master Clear pin enabled
#FUSES NOCPD //No EE protection
#FUSES NOPUT //No Power Up Timer
#FUSES IESO //Internal External Switch Over mode enabled
#FUSES FCMEN //Fail-safe clock monitor enabled
#use delay(clock=8000000)
/*
Pin defines
*/
#define led PIN_A5
#define driver_a PIN_C0
#define driver_b PIN_C1
/*
Variables
*/
/*
Function prototypes
*/
void set_drivers( int1 value );
#int_SSP // i2c activty
SSP_isr()
{
return;
}
void main(){
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
//setup_timer_2(T2_DIV_BY_1,255,1);
setup_timer_2(T2_DIV_BY_16, 124, 1); // 1000 Hz
setup_comparator(NC_NC_NC_NC);
//enable_interrupts(INT_SSP);
//enable_interrupts(GLOBAL);
setup_oscillator(OSC_8MHZ);
set_drivers( true );
set_pwm1_duty(31); // 25% duty cycle
output_low(PIN_C5);
output_low(PIN_C4);
output_low(PIN_C3);
output_low(PIN_C2);
output_high( led );
delay_ms(500);
output_low( led );
delay_ms(500);
output_high( led );
delay_ms(500);
output_low( led );
delay_ms(500);
while(1){
// left wheel foreward, right wheels not moving
setup_ccp1(CCP_PWM_H_H | CCP_PULSE_STEERING_A );
set_pwm1_duty(31); // 25% duty cycle
output_high( led );
delay_ms(1000);
// left wheels backward, right wheels not moving
setup_ccp1(CCP_PWM_H_H | CCP_PULSE_STEERING_B );
set_pwm1_duty(31); // 25% duty cycle
output_low( led );
delay_ms(1000);
}
}
/*
Funtion boddies
*/
void set_drivers( values ){
if( values ){
output_high( driver_a );
output_high( driver_b );
}
else{
output_low( driver_a );
output_low( driver_b );
}
}
|
_________________ checkout my site: www.ymoona.com/wiki |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|