Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
lol OK,, uhmmmm im new with the programming guys-sorry for asking alot of silly questions...just want to make sure i do it right this time. I have like a month and 1week left be80be.
void main()
{
// setup the [B]PIC 18F1320[/B]
OSCCON = 0x72; // internal osc, 8MHz
PORTA = 0;
[COLOR="Red"]TRISA = 0b10000010;[/COLOR] // RA7 high imp, RA3 is serial out,
// RA1 is ADC input measuring VR1
PORTB = 0;
INTCON2 = 0; // PORTB pullups ON
TRISB = 0b00000000; // PORTB not used
[COLOR="Indigo"] ADCON0 = 0b00000101; // ADC ON, RA1 is ADC input
ADCON1 = 0b01111101; // AN1 is ADC input
ADCON2 = 0b10100010; // right justify, [B][I]8Tad[/I][/B], 32Tosc[/COLOR]
T1CON = 0b00010001; // TMR1 is ON, 1:2 prescale, =1MHz
T3CON = 0b00010001; // TMR3 is ON, 1:2 prescale, =1MHz
// main loop here;
while(1)
{
// wait for 2 seconds, uses TMR1 free running at 1Mhz
while(!PIR1.TMR1IF); // wait for TMR1 overflow
PIR1.TMR1IF = 0; // clear overflow flag
LATA = 0; // all LEDs off
bres += 65536; // add 65536uS to bres value
if(bres >= 2000000) // if reached 2 seconds!
{
bres -= 2000000; // subtract 2 seconds, keep error
// flash Junebug LED1, RA0=1 RA6=0 RA7=hiimpedance
LATA.F0 = 1; // LED on
// read the ADC voltage RA1 (Sharp GP2 sensor)
ADCON0.F1 = 1; // set GO bit, start doing ADC
while(ADCON0.F1); // wait until ADC done
calc_distance(); // convert ADC value to distance
send_serial_message(); // send message back to PC!
}
}
}
[COLOR="Red"]TRISA = 0b10000010;[/COLOR] // RA7 high imp, RA3 is serial out,
// RA1 is ADC input measuring VR1
PORTB = 0;
INTCON2 = 0; // PORTB pullups ON
TRISB = 0b00000000; // PORTB not used
PORTB = 0;
WPUB = 1;
RABPU = 0;
[COLOR="Indigo"]ADCON0 = 0b00000101; // ADC ON, RA1 is ADC input
ADCON1 = 0b01111101; // AN1 is ADC input
ADCON2 = 0b10100010; // right justify, 8Tad, 32Tosc[/COLOR]
ADCON0 = 0b10000101; // bit 7 right justify,analogue channel select bits bits5-2 0001=AN1,ADC ON, RA1 is ADC input
ADCON1 = 0b00100000; //bits6-4 fosc/32
GetDeviceInfo GetDeviceInfo is online now
Member
Join Date: Jun 2009
Posts: 94
Default
Your not at programming yet, as the hardware isn't proven.
Here's a contemplation;
If you issue the IR radiation, and at the same time start an RC charge ramp. The detector then would cease and hold the charge, for the micro to AD convert, or drain the charge at a different rate that is complatable with the micro.
You will need a high power emitter and a sensitive reciever.
Another approach could be to charge a capacitive gate for the TOF duration, then inspect the gate effect.
Your problem is not in the pics timers, as you would only use them to time the sampling rate, but in the gating of your signals used to capture the TOF.