CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Software serial communication using Analog Comparator

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
djpark



Joined: 02 Mar 2004
Posts: 49

View user's profile Send private message

Software serial communication using Analog Comparator
PostPosted: Mon Mar 14, 2005 3:33 am     Reply with quote

I am in a project which runs PIC12F675 on 2.5V, serial communication through a device which gives out only about 0.1V high while it can take full Vdd.

Due to the space contraint, I am not able to use any other parts to amplify the voltage higher. So I am hoping to use the analog voltage comparator to determine hi/lo at the boundary of 0.1V and hopefully feed to serial routine.

Is it possible to use "#use rs232" to read the result of the comparator output (C1OUT) as RX input? The real low voltage input is connected to A1.

I am attaching the source code below and hope to get some advice if this can actually work or any better advice.

Thanks in advance.

-- dj

Code:

#include <12F675.h>
#fuses NOWDT, INTRC_IO, NOCPD, NOPROTECT, NOMCLR, NOPUT, BROWNOUT
#use delay(clock=4000000)

// real input is on PIC_A1
#define RX_PIN PIN_A2
#define TX_PIN PIN_A4
#use rs232(baud=1200, xmit=TX_PIN, rcv=RX_PIN, INVERT)

void main()
{
   char c;

   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);

   setup_comparator(A1_VR_OUT_ON_A2);
   setup_vref (VREF_LOW | 1);   // 0.1V from Vdd=2.5V

   while (1)
   {
      if (kbhit())
      {
         c = getc();
         putc(c);
      }
      delay_us(10);
   }

}
Ttelmah
Guest







PostPosted: Mon Mar 14, 2005 6:17 am     Reply with quote

Basic answer is you will have to write your own code, and the data rate will need to be fairly low. The internal serial code, just reads a logc input. To use the ADC pin, you need to perform a full ADC conversion, to get a reading, and the time delays associated with this, will limit the data rate, and will alter the 'point' in the serial stream where the sample is being taken.

Best Wishes
djpark



Joined: 02 Mar 2004
Posts: 49

View user's profile Send private message

PostPosted: Mon Mar 14, 2005 6:26 am     Reply with quote

Thanks for the comment.

I am expecting that the comparator will compare the voltage on PIN_A1 against Vref, and give out the full Vdd logic output to PIN_A2. Thus no ADC is involved.

Come to think of it, the PIN_A2 will be output from the result of C1OUT and rs232 will use the pin as input. So it may not work after all.

Perhaps, tie PIN_A2 to PIN_A3 and use PIN_A3 as rs232 input may work.

-- dj
Ttelmah
Guest







PostPosted: Mon Mar 14, 2005 10:25 am     Reply with quote

Sorry, I misread, and thought you were trying to use the ADC. The comparator might be possible, but whether the off the shelf code will support it, is very 'debatable'. I think the only way to find out will be to actually test this, perhaps using the MPLAB simulator, and setting up an input file to generate the expected data pattern, and then stepping through, and seeing if the right byte is assembled.

Best Wishes
languer



Joined: 09 Jan 2004
Posts: 144
Location: USA

View user's profile Send private message

PostPosted: Mon Mar 14, 2005 3:54 pm     Reply with quote

In theory this should work. The comparator is in no way affected by the software. Actually, I've used this as a 'sort-of' data slicer (or RSSI function) on inexpensive RF receiver modules.

You are not incorporating any type of hysteresis however, if your input signal is not properly defined, you could get all sort of 'chatter'.

But in principle it would be no different than adding an external comparator to achieve this, the soft-RS232 does not even know it is there.
Ttelmah
Guest







PostPosted: Mon Mar 14, 2005 4:29 pm     Reply with quote

You could add a little hysteresis, with something like a 10M resistor from the comparator output pin to the Vref pin.
The more you look at this, the more it should be possible. Even the required TRIS settings are compatible!...
Potentially (since you are using soft RS232), you can set the polarity of the comparator output the right way to give the hysteresis, and then invert the RS232 reception if necessary.

Best Wishes
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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