 |
 |
| View previous topic :: View next topic |
| Author |
Message |
viethung_tdh
Joined: 31 May 2014 Posts: 18
|
|
Posted: Wed Jun 25, 2014 9:19 pm |
|
|
| jeremiah wrote: | | viethung_tdh wrote: |
But In CCS help.
output_high( )
--------------------------------------------------------------------------------
Syntax:
output_high (pin)
Parameters:
Pin to write to. Pins are defined in the devices .h file. The actual value is a bit address. For example, port a (byte 5) bit 3 would have a value of 5*8+3 or 43. This is defined as follows: #define PIN_A3 43. The PIN could also be a variable. The variable must have a value equal to one of the constants (like PIN_A1) to work properly. The tristate register is updated unless the FAST_I0 mode is set on port A. Note that doing I/0 with a variable instead of a constant will take much longer time.
Function:
Sets a given pin to the high state. The method of I/O used is dependent on the last USE *_IO directive.
Availability:All devices.
Requires: Pin constants are defined in the devices .h file |
None of that says it is required. What it is saying is fast_io changes how the methods work. They work differently depending on if fast_io, standard_io, and fixed_io are used. I've been programming for a very long time using output_high and output_low and have never needed to use fast_io (not that you can't use it...but not required).
As an example:
Without fast_io, output_high(PIN_A1) does the following:
Sets the TRIS for A1 to output
Sets the level of A1 to high
Conversely, output_high() with fast_io set does the following:
Sets the level of A1 to high
See the difference in the two settings? In both scenarios, output_high() worked, but they worked differently.
Make sense? |
So why? when i add #use fast_io(A)==>mtouch and module pwm not running!
and when i dont add #use fast_io(A)==> Mtouch have problem (value (dem ) allway > temp) and pwm will keep running forever regardless signals from mtouch
| Code: |
int16 get_touch()
{
output_high(PIN_A0);
set_adc_channel(0);
delay_us(10);
output_low(PIN_A4);
output_float(PIN_A4);
set_adc_channel(3);
delay_us(10);
return read_adc();
}
/*==========================Ham doc gia tri =============================*/
void touch_read()
{
Touch=get_touch();
if(Touch<temp) dem++;
}
/*=========================Ham duty cycle================================*/
void duty_cycle()
{
switch(dem)
{
case 1:
{set_pwm1_duty(113);break;}
case 2:
{set_pwm1_duty(56);break;}
case 3:
{set_pwm1_duty(13);break;}
case 4:
{set_pwm1_duty(56);break;}
case 5:
{set_pwm1_duty(113);break;}
}
}
/*=======================================================================*/
/***************************** Ham chinh *********************************/
void main()
{
int16 temp1;
setup_ccp1(CCP_PWM);
setup_timer_2(T2_DIV_BY_16, 112, 1);
setup_adc_ports(sAN1|sAN0|VSS_VDD);
setup_adc(ADC_CLOCK_DIV_8);
output_high(PIN_A5);
for(i=0;i<32;i++)// lay mau 32 lan
{
temp1 += get_touch();
delay_us(8);
}
temp = temp1/32 ;
while(TRUE)
{
delay_us(10);
touch_read();
duty_cycle();
delay_ms(5000);
if(dem==5)dem=1;
}
}
/*************************************************************************/
| [/quote] |
|
 |
jeremiah
Joined: 20 Jul 2010 Posts: 1411
|
|
Posted: Thu Jun 26, 2014 7:40 am |
|
|
| viethung_tdh wrote: |
So why? when i add #use fast_io(A)==>mtouch and module pwm not running!
and when i dont add #use fast_io(A)==> Mtouch have problem (value (dem ) allway > temp) and pwm will keep running forever regardless signals from mtouch
|
Well if you turn on fast_io and things stop working that is usually caused by various issues:
1. You could be incorrectly handling TRIS for the peripherals that you are using. Without fast_io, the compiler sets the correct pin directions (input vs output) for you. Once you enable fast_io, you have to make sure you handle TRIS not only for your digital ins/outs, but for your peripherals as well. 99% of issues with fast_io come from incorrect usage and probably 99% of the projects out there don't need to use fast_io.
2. This is less likely, but the compiler could have a bug in the addressing of the TRIS register or you could have the wrong address for the TRIS register if you are setting it yourself.
3. Some chips have an errata that specifies that bit operations on some register fail and only byte operations can be used. I didn't check your chip for this, but it is also a fairly rare thing.
My honest guess on why turning on fast_io causes your PWM to stop running is mishandling of the TRIS for it. Since leaving off fast_io gives the compiler the job of handling TRIS and you get output on the PWM (granted I know it is continuous, but it is running at least) and it does output something, that signals to me that when you turn on fast_io, you are making a mistake with how you handle TRIS. |
|
 |
|
|
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
|