|
|
View previous topic :: View next topic |
Author |
Message |
Guest
|
How long does it take a PIC16LF818 to complete power up? |
Posted: Thu Oct 09, 2008 9:26 am |
|
|
Hi,
I have a main processor board that it is in sleep mode, it wakes up every 2 seconds and provide a 3.3V out from one of the pin(RB3) for 200ms. The purpose of this is to turn on a pressure sensor to see if there is enough pressure, if it is the unit will turn on, if it is not, the unit go back to sleep. The sensor output connect to C1 of the unit. I want to use the a second processor to simulate as pressure sensor, so I use the PIC16LF818.
The question is
How long will it take the PIC16LF818 to complete power up? Is the above 200ms will enough time for the PIC16LF818 complete power up?
The function of my code is as follow:
As soon as the pic power up, reads RA0 (this is the simulate board) to see if there is a value greater than 0, then generate a 13 pulses (in either 40uS or 80uS or combination on each pulses) to simulate a serial pressure data feed to RC1 of the main processor board. if the the main board see serial data in RC1 then it will turn on, if there is no serial data shown then, it will go back to sleep.
Code: | #include <16f818.h>
//#include <16f877.h> //change PIC
#device ADC=10
#fuses XT,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
//#use rs232(baud=9600, xmit=Pin_c6)
marker_40usec(void)
{
output_high(pin_b2);
delay_us(40);
}
//40 usec data pulse
data_40usec(void)
{
output_low(pin_b2);
delay_us(40);
}
data_80usec(void)
{
output_low(pin_b2);
delay_us(80);
}
//================================================
pressure_6(void)
{
output_high(pin_b2);
delay_us(80);
data_80usec(); //0
marker_40usec();
data_80usec(); //1
marker_40usec();
data_80usec(); //2
marker_40usec();
data_80usec(); //3
marker_40usec();
data_80usec(); //4
marker_40usec();
data_80usec(); //5
marker_40usec();
data_80usec(); //6
marker_40usec();
data_80usec(); //7
marker_40usec();
data_80usec(); //8
marker_40usec();
data_80usec(); //9
marker_40usec();
data_80usec(); //10
marker_40usec();
data_40usec(); //11
marker_40usec();
data_40usec(); //12
marker_40usec();
data_40usec(); //13
marker_40usec();
data_40usec(); //14
marker_40usec();
data_40usec(); //15
output_high(pin_b2);
delay_us(80);
}
//=========================================
pressure_5(void)
{
output_high(pin_b2);
delay_us(80);
data_80usec(); //0
marker_40usec();
data_80usec(); //1
marker_40usec();
data_80usec(); //2
marker_40usec();
data_80usec(); //3
marker_40usec();
data_80usec(); //4
marker_40usec();
data_80usec(); //5
marker_40usec();
data_80usec(); //6
marker_40usec();
data_80usec(); //7
marker_40usec();
data_80usec(); //8
marker_40usec();
data_80usec(); //9
marker_40usec();
data_40usec(); //10
marker_40usec();
data_40usec(); //11
marker_40usec();
data_40usec(); //12
marker_40usec();
data_40usec(); //13
marker_40usec();
data_40usec(); //14
marker_40usec();
data_40usec(); //15
output_high(pin_b2);
delay_us(80);
}
//==================================================
pressure_4(void)
{
output_high(pin_b2);
delay_us(80);
data_80usec(); //0
marker_40usec();
data_80usec(); //1
marker_40usec();
data_80usec(); //2
marker_40usec();
data_80usec(); //3
marker_40usec();
data_80usec(); //4
marker_40usec();
data_80usec(); //5
marker_40usec();
data_80usec(); //6
marker_40usec();
data_80usec(); //7
marker_40usec();
data_80usec(); //8
marker_40usec();
data_40usec(); //9
marker_40usec();
data_40usec(); //10
marker_40usec();
data_40usec(); //11
marker_40usec();
data_40usec(); //12
marker_40usec();
data_40usec(); //13
marker_40usec();
data_40usec(); //14
marker_40usec();
data_40usec(); //15
output_high(pin_b2);
delay_us(80);
}
//+++++++++++++++++++++++++++++++++++++++++++++++
pressure_3(void)
{
output_high(pin_b2);
delay_us(80);
data_80usec(); //0
marker_40usec();
data_80usec(); //1
marker_40usec();
data_80usec(); //2
marker_40usec();
data_80usec(); //3
marker_40usec();
data_80usec(); //4
marker_40usec();
data_80usec(); //5
marker_40usec();
data_40usec(); //6
marker_40usec();
data_80usec(); //7
marker_40usec();
data_40usec(); //8
marker_40usec();
data_40usec(); //9
marker_40usec();
data_40usec(); //10
marker_40usec();
data_40usec(); //11
marker_40usec();
data_40usec(); //12
marker_40usec();
data_40usec(); //13
marker_40usec();
data_40usec(); //14
marker_40usec();
data_40usec(); //15
output_high(pin_b2);
delay_us(80);
}
//===========================================
pressure_2(void)
{
output_high(pin_b2);
delay_us(80);
data_80usec(); //0
marker_40usec();
data_80usec(); //1
marker_40usec();
data_80usec(); //2
marker_40usec();
data_80usec(); //3
marker_40usec();
data_80usec(); //4
marker_40usec();
data_80usec(); //5
marker_40usec();
data_80usec(); //6
marker_40usec();
data_40usec(); //7
marker_40usec();
data_40usec(); //8
marker_40usec();
data_40usec(); //9
marker_40usec();
data_40usec(); //10
marker_40usec();
data_40usec(); //11
marker_40usec();
data_40usec(); //12
marker_40usec();
data_40usec(); //13
marker_40usec();
data_40usec(); //14
marker_40usec();
data_40usec(); //15
output_high(pin_b2);
delay_us(80);
}
//=================================================
pressure_1(void)
{
output_high(pin_b2);
delay_us(80);
data_80usec(); //0
marker_40usec();
data_80usec(); //1
marker_40usec();
data_80usec(); //2
marker_40usec();
data_80usec(); //3
marker_40usec();
data_80usec(); //4
marker_40usec();
data_80usec(); //5
marker_40usec();
data_40usec(); //6
marker_40usec();
data_40usec(); //7
marker_40usec();
data_40usec(); //8
marker_40usec();
data_40usec(); //9
marker_40usec();
data_40usec(); //10
marker_40usec();
data_40usec(); //11
marker_40usec();
data_40usec(); //12
marker_40usec();
data_40usec(); //13
marker_40usec();
data_40usec(); //14
marker_40usec();
data_40usec(); //15
output_high(pin_b2);
delay_us(80);
}
//=====================================================
pressure_0(void)
{
output_high(pin_b2);
delay_us(80);
data_40usec(); //0
marker_40usec();
data_40usec(); //1
marker_40usec();
data_40usec(); //2
marker_40usec();
data_40usec(); //3
marker_40usec();
data_40usec(); //4
marker_40usec();
data_40usec(); //5
marker_40usec();
data_40usec(); //6
marker_40usec();
data_40usec(); //7
marker_40usec();
data_40usec(); //8
marker_40usec();
data_40usec(); //9
marker_40usec();
data_40usec(); //10
marker_40usec();
data_40usec(); //11
marker_40usec();
data_40usec(); //12
marker_40usec();
data_40usec(); //13
marker_40usec();
data_40usec(); //14
marker_40usec();
data_40usec(); //15
output_high(pin_b2);
delay_us(80);
}
main()
{
long adc_value;
set_tris_b(0xF0);
// output_low(pin_a5);
setup_port_a( ALL_ANALOG );
setup_adc( ADC_CLOCK_INTERNAL );
set_adc_channel( 0 );
while(1)
{
adc_value = read_adc();
delay_us(40);
// output_b(adc_value);
// delay_ms(100);
// printf("\n\r ADC_Value: %lu",adc_value);
//printf("OK");
if(adc_value >1000)
{
pressure_6();
}
else if(adc_value > 700)
{
pressure_5();
}
else if(adc_value > 400)
{
pressure_4();
}
else if(adc_value > 200)
{
pressure_3();
}
else if(adc_value > 100)
{
pressure_2();
}
else if(adc_value > 50)
{
pressure_1();
}
else
{
pressure_0();
}
}
}
|
|
|
|
Guest
|
|
Posted: Thu Oct 09, 2008 9:28 am |
|
|
Actually, there will be 15 pulses, not 13. |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Thu Oct 09, 2008 9:55 am |
|
|
A lot depends on the crystal you are using and how stable it needs to be for the work you want the PIC to do. If you use the PUT (power up timer) that will set the lower limit. Also look at the the speed of your reset circuit.
With care you should be able to get the PIC running in under 1ms. If you must start faster look at using a ceramic resonator or an RC circuit. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
asmallri
Joined: 12 Aug 2004 Posts: 1638 Location: Perth, Australia
|
|
Posted: Thu Oct 09, 2008 10:21 am |
|
|
Not the question you asked, but you could make this code far easier to read with some minor changes.
You can embed the marker in the data routine (significant reduction in user readable code). You can also use a common data function.
Code: |
data_pulse(int8 delay)
{
// do data pulse)
output_low(pin_b2);
delay_us(delay);
// do marker
output_high(pin_b2);
delay_us(40);
}
You could further reduce the user readable code size by defining constant arrays for each pressure value which contains the data delay value for each step. There you pressure code sequence is a for loop
for x = 0 to number of pulses - 1
data_pulse(pressure6[x]);
|
_________________ Regards, Andrew
http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!! |
|
|
|
|
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
|