|
|
View previous topic :: View next topic |
Author |
Message |
tyrael Guest
|
TRIS are not respected in CCS, how can I change it... |
Posted: Fri Feb 17, 2006 4:19 pm |
|
|
When trying to put TX to in(High impedance), I is still working as out, im using fast_io, this is the same with the P1B PWM out in half bridge, I put the code, Its commented Thank for the help, CCS team!!!
The problem is in almost the final part of the Step function, everything is based on the AN906, thanks!!!!!
#include <18F4550.h>
#device adc=8
#fuses NOWDT,WDT128,HSPLL, NOPROTECT, BROWNOUT_NOSL, NOBROWNOUT,\
BORV20, NOPUT, NOCPD,NOSTVREN, NODEBUG, NOLVP, NOWRT, NOWRTD, NOIESO, NOFCMEN, NOPBADEN, NOWRTC,\
NOWRTB, NOEBTR, NOEBTRB, NOCPB, MCLR, NOLPT1OSC, NOXINST, PLL5, CPUDIV1
#use delay(clock=48000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
#use fast_io(A)
#use fast_io(B)
#use fast_io(C)
#use fast_io(D)
typedef short BOOL;
enum STEP_STATE
{
SS_STOP = 0,
SS_PAUSE,
SS_LEFT,
SS_RIGHT
};
enum STEP_MODE
{
SM_FULL_1PH = 0,
SM_FULL_2PH ,
SM_HALF,
SM_MICRO
};
enum STEP_TIME
{
ST_ONE = 0x01,
ST_TWO = 0x02,
ST_THREE = 0x04,
ST_FOUR = 0x08
};
const struct STEP_PARAM
{
INT iStepsCicle;
INT iStepSequence[8];
}SP_MODES[4] = {
{4, { ST_ONE, ST_TWO, ST_THREE, ST_FOUR}}, // FULL_1PH
{4, { ST_ONE|ST_TWO, ST_TWO|ST_THREE, ST_THREE|ST_FOUR, ST_FOUR|ST_ONE}}, // FULL_2PH
{8, { ST_ONE, ST_ONE|ST_TWO, ST_TWO, ST_TWO|ST_THREE, // HALF_STEP
ST_THREE, ST_THREE|ST_FOUR, ST_FOUR, ST_FOUR|ST_ONE}} // HALF_STEP
{8, { ST_ONE|ST_TWO, ST_TWO|ST_THREE, ST_TWO|ST_THREE, ST_THREE|ST_FOUR,
ST_THREE|ST_FOUR, ST_FOUR|ST_ONE, ST_FOUR|ST_ONE, ST_ONE|ST_TWO }} // FULL_2PH
};
const INT iPWMControl[8] = {0,0,1,1,0,0,1,1}; // PARA LOS TRIS SEGUN LOS PASOS
enum MICROSTEP_MODE
{
MSM_MICRO_4,
MSM_MICRO_8,
MSM_MICRO_16,
MSM_MICRO_32
};
const struct MICROSTEP_PARAM
{
INT iMicroSteps;
LONG lMicroSequencePWM[32];
}MSM_MODES[4] = {
{4, {1023, 828, 316, 0}}, // CALCULADO SEGUN LA FORMULA DE AN906
{8, {1023, 961, 784, 511, 178, 0}},
{16,{1023, 1006, 954, 870, 756, 616, 456, 280, 94, 0}}
{32,{1023, 1018, 1005, 982, 950, 909, 861, 804, 740, 670, 593, 511, 424, 335, 241, 146, 49, 0}}
};
// STATE VARIABLES
INT iMicroStepPos = 0; // Numero de el micro paso dentro de las dos fases
INT iStepPos = 0; // Numero para el paso de control
STEP_STATE ssState = SS_STOP;
STEP_MODE smMode = SM_HALF;
MICROSTEP_MODE msmMode = MSM_MICRO_4;
BOOL bChange = FALSE; // Variable aux para saber cuando hay que ir de mas a menos o de menos a mas en el arreglo
INT PWMA; // Hacia el tris de P1A - > TRISC.2
INT PWMB; // Hacia el tris de P1B - > TRISC.5
void SetMode( STEP_MODE Mode )
{
if(Mode != SM_MICRO )
{
}
else
{
setup_timer_2(T2_DIV_BY_1, 0xFF, 1);
setup_ccp1(CCP_PWM_HALF_BRIDGE|CCP_PWM_H_L);
set_tris_c(0xBF);
set_tris_d(0xFF);
}
smMode = Mode;
}
void SetMicroMode( MICROSTEP_MODE Mode )
{
msmMode = Mode;
}
void SetState( STEP_STATE State )
{
ssState = State;
}
void Step( void )
{
if( ssState == SS_PAUSE )
return;
if( ssState == SS_STOP )
{
output_b(0x00);
return;
}
if( ssState == SS_LEFT )
{
if( smMode != SM_MICRO )
{
--iStepPos;
if( iStepPos == -1 )
iStepPos = SP_MODES[smMode].iStepsCicle-1;
}
else
{
if(bChange)
--iMicroStepPos;
else
++iMicroStepPos;
if( iMicroStepPos == -1 || iMicroStepPos == (MSM_MODES[msmMode].iMicroSteps/2)+2 )
{
--iStepPos;
bChange = !bChange;
if(bChange)
iMicroStepPos-=2;
else
iMicroStepPos+=2;
}
if( iStepPos == -1 )
iStepPos = SP_MODES[smMode].iStepsCicle-1;;
}
}
if( ssState == SS_RIGHT )
{
if( smMode != SM_MICRO )
{
++iStepPos;
if( iStepPos == SP_MODES[smMode].iStepsCicle )
iStepPos = 0;
}
else
{
if(bChange)
++iMicroStepPos;
else
--iMicroStepPos;
if( iMicroStepPos == -1 || iMicroStepPos == (MSM_MODES[msmMode].iMicroSteps/2)+2 )
{
++iStepPos;
bChange = !bChange;
if(bChange)
iMicroStepPos+=2;
else
iMicroStepPos-=2;
}
if( iStepPos == SP_MODES[smMode].iStepsCicle )
iStepPos = 0;
}
}
if( smMode == SM_MICRO )
{
PWMA = iPWMControl[iStepPos];
PWMB = !PWMA;
/* AQUI EL PROBLEMA, el TRISD no sirve!!!!!*/
set_tris_c(0xBF);//--> High impedance(Input) for P1A, Works
set_tris_d(0xFF);//--> High Impedance(Input) for P1B, Dont work, still send PWM
set_pwm1_duty(MSM_MODES[msmMode].lMicroSequencePWM[iMicroStepPos]);
printf("POS = %u - DUTY = %lu \r\n6",iMicroStepPos, MSM_MODES[msmMode].lMicroSequencePWM[iMicroStepPos]);
}
output_b(SP_MODES[smMode].iStepSequence[iStepPos]);
}
void main()
{
INT DSE = 0;
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
set_tris_b(0x00);
SetState(SS_RIGHT);
SetMode(SM_MICRO);
SetMicroMode(MSM_MICRO_32);
while(1)
{
Step();
output_d(DSE++); // WHEN TRISD = FF, all should off, but P1B not
delay_ms(100);
}
} |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Feb 17, 2006 4:36 pm |
|
|
From the 18F4550 data sheet:
Quote: | Some peripherals override the TRIS
bit to make a pin an output, while other
peripherals override the TRIS bit to
make a pin an input | .
And also this:
Quote: | The contents of the TRISC register are affected by
peripheral overrides. Reading TRISC always returns
the current contents, even though a peripheral device
may be overriding one or more of the pins. |
|
|
|
tyrael Guest
|
Thanks |
Posted: Fri Feb 17, 2006 9:23 pm |
|
|
Ok, thanks a lot, I will be more aware, but what about portD and ECCP, I have read them in 4550 datasheet, and says I have to configure the tris manually and there is no problem with P1A, the problem is P1B this is not respected, Unless another module is on, but i guest i turn off everything but ECCP, thanks a lot anyway!!!! |
|
|
tyrael Guest
|
Resumen |
Posted: Fri Feb 17, 2006 9:26 pm |
|
|
Resuming the ploblem with P1A and P1B is I want P1A High impedance, P1B With PWM, do microstepping and then viseversa, when i put P1A at high impedance making it input it works, but P1B is still modulating when it's tris is Input, thanks |
|
|
tyrael Guest
|
|
Posted: Sat Feb 18, 2006 9:48 am |
|
|
program with just the problem
#include <18F4550.h>
#device adc=8
#fuses NOWDT,WDT128,HSPLL, NOPROTECT, BROWNOUT_NOSL, NOBROWNOUT, BORV20, NOPUT, NOCPD, NOSTVREN, NODEBUG, NOLVP, NOWRT, NOWRTD, NOIESO, NOFCMEN, NOPBADEN, NOWRTC, NOWRTB, NOEBTR, NOEBTRB, NOCPB, MCLR, NOLPT1OSC, NOXINST, PLL5, CPUDIV1
#use delay(clock=48000000)
void main()
{
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
set_tris_c(0x00);
set_tris_d(0x00);
setup_timer_2(T2_DIV_BY_1, 0xFF, 1); // 10 bits, 40Khz, 1020 max aprox
setup_ccp1(CCP_PWM_HALF_BRIDGE|CCP_PWM_H_L);
while(1)
{
set_tris_c(0x00);
set_tris_d(0x00);
set_pwm1_duty(100); // 10% aprox // 3 segundos con PWM P1A y P1B
delay_ms(3000);
set_tris_c(0xFF); // Las quiero en Alta impedancia de entrada por 3 segundos
set_tris_d(0xFF); // P1A en el tris c si se queda en alta impedancia, pero el P1B, de tris D no, ese es mi problema
delay_ms(3000);
}
} |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Feb 18, 2006 12:50 pm |
|
|
According to the 18F4550 data sheet, it should work.
I compiled your program with PCH vs. 3.242, and the compiler is
making correct code:
Code: | ...... set_tris_c(0xFF); // Las quiero en Alta impedancia...
00BA: MOVLW FF
00BC: MOVWF F94
..... set_tris_d(0xFF); // P1A en el tris c si se queda...
00BE: MOVWF F95 |
There could be a hardware bug in the PIC. You should test it some more
and if you can't find a solution, then add an external buffer chip so you
can tristate the PWM signal. |
|
|
tyrael Guest
|
THANKS |
Posted: Sat Feb 18, 2006 3:00 pm |
|
|
ok thanks you very much, well i been trying almost everything, i'm going to use a multiplexor, what i want was drive a PWM and make the other High using a pull up resistor when tristate, better I'll use a out put pin to drive the mux inplace of the tris register and send high or PWM directly, thanks a lot for your time and help.
Atte: Victor Daniel Jimenez Camacho |
|
|
|
|
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
|