Académique Documents
Professionnel Documents
Culture Documents
Author Message
I've been using higher end pics in the past, and now I'm playing with a MELABS x3 board. I've
gotten everything to work except for the pot measurement. It appears to use the RC time
constant to measure the change of resistence.
I've read in Myke Predko's book how to do it, but my code doesn't seem to work at all. The PIC
basic hex file works, using the POT command so I know the hardware is fine.
Code:
#use rs232(baud = 9600, xmit = PIN_B2, rcv = PIN_B1) // Setup the on boards USART
// Function Prototype
int pot_read(void);
int potval;
void main(void)
{
//int CharPresent;
port_b_pullups(TRUE);
set_tris_a(0x00);
1 от 5 01.3.2007 г. 10:37
CCS :: View topic - ADCless POT reading using a 16F628 http://ccsinfo.com/forum/viewtopic.php?t=27191&highlight=inte...
set_tris_b(0b10000010);
printf("TEST RS232\r\n");
lcd_init();
//enable_interrupts(INT_RB); // Enable Status Chang on B Interrupt
//enable_interrupts(GLOBAL); // Enable Interrupts to be used.
for (;;)
{
output_high(LED1);
delay_ms(250);
output_low(LED1);
output_high(LED2);
delay_ms(250);
output_high(LED1);
delay_ms(500);
output_low(LED1);
output_low(LED2);
delay_ms(500);
potval = pot_read();
printf(putc_lcd,"%x",potval);
}
}
So basically it just hangs in the while loop I assume. Now that I look at the code is it because I
don't have a roll over for my int i? I thought it would automatically roll over....
Anyway, the way I coded the pot_read() function was that it put out a high on the B0 pin and
delay 5 us for charging of the cap. Then I change my tris to make it an input, the capacitor
should start to discharge to ground, then wait for the trigger point on the high to low transition.
approx 2.5 or 1.5 V.
Regards,
David.
2 от 5 01.3.2007 г. 10:37
CCS :: View topic - ADCless POT reading using a 16F628 http://ccsinfo.com/forum/viewtopic.php?t=27191&highlight=inte...
charging time for the capacitor. Compare the amount of time that
they charge the capacitor to the amount of time that you're using.
Plug the values of the cap and trimpot from the labx3 schematic
into their equation. What time value do you get ?
Besides that problem, the rest of your pot_read() routine doesn't work
the way the Pot command does in PicBasic. If you want to translate
the PicBasic Pot command to C, one good way to do it is to compile
a Picbasic program which uses that command, and then look at the .LST
file. They put comments in there which explain what the ASM code is
doing. You may not understand all of it, but I think you should be
able to get the idea of how they do the measurement. Example:
Code:
POT
call CONVPIN ; Convert pin to FSR and bit mask
POTT
movwf RM1 ; Save bit mask
call HIGHT ; Set pin high to charge cap
Hey, Great help thanks. Apprently the guy in the that wrote that book forgot to mention you
Joined: 31 May 2006
Posts: 2 needed to discharge the capacitor.
Now I've got another question I did a delay_ms(2.5) ; And it put a delay of about 9.28 seconds.
Whats the deal with that is that a bug or something? I've got compiler 3.42.
Thanks,
David
Code:
3 от 5 01.3.2007 г. 10:37
CCS :: View topic - ADCless POT reading using a 16F628 http://ccsinfo.com/forum/viewtopic.php?t=27191&highlight=inte...
while (POTPIN == 1) // Do loop will the storge charge is more than 2.5 Vdc
{
i++; // Increment Counter 0hms = 01 hex
output_low(POT); // Set ouput to discharge cap a bit
set_tris_b(0b10000010); // set the i/o port to output
delay_us(10); // wait a bit for it to discharge some.
set_tris_b(0b10000011); // I/O to input to check for the switch point
}
>>Arlof said:
Joined: 14 Mar 2006
Posts: 10 >>Now I've got another question I did a delay_ms(2.5) ; And it put a >>delay of about 9.28
seconds. Whats the deal with that is that a bug or >>something? I've got compiler 3.42.
>>Thanks,
>>David
Hmm, according to the "Compiler Updates" webpage the latest versions are Version 3.249 &
Version 3.236 . Perhaps you have a typo.
Check the parameter value for delay_ms() again; 2.5 is not within the allowed parameter
ranges.
I did try 2.1, 2.2 ... 3.5 and only 2.5, 3 and 3.5 gave any ASM result.
I did not try to decipher the resulting delay. The values 2.1 and others caused the compiler to
not generate any code.
------------------------------------------------------------------------------
Syntax:
delay_ms (time)
Parameters:
time - a variable 0-255 or a constant 0-65535
HTH,
Leef_me
Code:
#include "C:\Documents and Settings\Lee\My Documents\rc_signal\rc.h"
void main()
{
delay_ms(100);
output_float (PIN_A3);
delay_ms(2.5);
output_float (PIN_A3);
4 от 5 01.3.2007 г. 10:37
CCS :: View topic - ADCless POT reading using a 16F628 http://ccsinfo.com/forum/viewtopic.php?t=27191&highlight=inte...
The 'delay' functions, accept _integer_ values only. My guess would be that 2.5, gets encoded by
the compiler to a float, and then the first two bytes of this get taken and treated as an integer.
This would be '0x2080', allowing for the byte order used in the float, which ought to give 8.32
seconds. However the behaviour with a float is completely undefined, so this is only a guess.
If you want to delay for 2.5mSec, then code this as delay_us(2500).
Best Wishes
Page 1 of 1
5 от 5 01.3.2007 г. 10:37