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 support@ccsinfo.com

CVD code references

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



Joined: 17 Oct 2012
Posts: 3

View user's profile Send private message

CVD code references
PostPosted: Wed Oct 17, 2012 9:34 pm     Reply with quote

I'm trying to work on CVD code...has anyone have on it? If you have any code or circuit examples, I would love to see them.

Also, is it possible to control "C hold" with CCS-C function? If there is, what would it be?

Last, I bought DM183026-2 KIT from Microchip. Is there any example of CCS-C code that is used for this Kit? The manual of the kit only provides Hitech-C codes.

Thank you!!
Ttelmah



Joined: 11 Mar 2010
Posts: 19467

View user's profile Send private message

PostPosted: Thu Oct 18, 2012 1:33 am     Reply with quote

There is nothing 'rocket science' about this. Every function needed, is standard code.
Sequence involved is:
Code:

set_adc_channel(CH_FOR_Vdd); //depends on the PIC
delay_us(DATA1);
output_low(SENSE_PIN); //according to what pin you are using
output_float(SENSE_PIN);
set_adc_channel(CH_FOR_SENSE); //adc channel number for the pin
delay_cycles(GUESS); //This has to be tweaked to get it to work
val=read_adc();

Now, some PIC's have Vdd available on the ADC multiplexer internally, while on others, another dummy pin needs to be used for this.
Also you need to be using the 10bit ADC mode, and an int16 for 'val' to get any reasonable resolution.
You need to delay long enough after selecting 'Vdd', for the internal hold capacitor to charge to Vdd, depends on the internal resistances of the chip - in the data sheet - and before the reading, another delay is needed, to allow Chold time to charge to the external signal.
The delay needed here, again depends on the PIC chosen. Keep as short as possible (go slightly below the recommended minimum, just reduces accuracy of the sampling, but improves response in this case).
Chold is _hardware_ it is the internal hold capacitor for the ADC. Nothing can change it, except choosing different chips. Later PIC's tend to have smaller values for this, allowing faster charging.
'Read the data sheet'.


Best Wishes
unisaco



Joined: 03 Dec 2012
Posts: 6

View user's profile Send private message Yahoo Messenger

PostPosted: Sun Dec 30, 2012 10:04 pm     Reply with quote

Ttelmah wrote:
There is nothing 'rocket science' about this. Every function needed, is standard code.
Sequence involved is:
Code:

set_adc_channel(CH_FOR_Vdd); //depends on the PIC
delay_us(DATA1);
output_low(SENSE_PIN); //according to what pin you are using
output_float(SENSE_PIN);
set_adc_channel(CH_FOR_SENSE); //adc channel number for the pin
delay_cycles(GUESS); //This has to be tweaked to get it to work
val=read_adc();

Now, some PIC's have Vdd available on the ADC multiplexer internally, while on others, another dummy pin needs to be used for this.
Also you need to be using the 10bit ADC mode, and an int16 for 'val' to get any reasonable resolution.
You need to delay long enough after selecting 'Vdd', for the internal hold capacitor to charge to Vdd, depends on the internal resistances of the chip - in the data sheet - and before the reading, another delay is needed, to allow Chold time to charge to the external signal.
The delay needed here, again depends on the PIC chosen. Keep as short as possible (go slightly below the recommended minimum, just reduces accuracy of the sampling, but improves response in this case).
Chold is _hardware_ it is the internal hold capacitor for the ADC. Nothing can change it, except choosing different chips. Later PIC's tend to have smaller values for this, allowing faster charging.
'Read the data sheet'.


Best Wishes

Sorry for my noodle, but can you show me the full of this code ?
In my mind, for this code, we compare val value with some constant ?, for ex:
Code:

val=read_adc();
if (val > 200)
 {
     output_high(...)
 } else {
    output_low(...)

Now I need to help that how can I make just only 1 LED blink within 1 mtouch button.
Thanks for your guidelines very much.
Ttelmah



Joined: 11 Mar 2010
Posts: 19467

View user's profile Send private message

PostPosted: Mon Dec 31, 2012 2:23 am     Reply with quote

The starting point is the Microchip application note.
No, you'd probably not want to use a constant. You'd need to have some 'setup' code, and perform a reading without the button touched, and then again with it touched, and then calculate a value perhaps half way between these results, and use this as your 'detection' point. The capacitance _will_ change too much with the weather, and drift in the other components, for a constant to reliably be used.

Best Wishes
unisaco



Joined: 03 Dec 2012
Posts: 6

View user's profile Send private message Yahoo Messenger

PostPosted: Mon Dec 31, 2012 11:01 am     Reply with quote

Ttelmah wrote:
The starting point is the Microchip application note.
No, you'd probably not want to use a constant. You'd need to have some 'setup' code, and perform a reading without the button touched, and then again with it touched, and then calculate a value perhaps half way between these results, and use this as your 'detection' point. The capacitance _will_ change too much with the weather, and drift in the other components, for a constant to reliably be used.

Best Wishes

Sorry, but have you done this code ? and is it running as well ?
Based on this code, I can make my application run (toggle LED each time touch), but when I touch to any A/DC input not yet be used in 16F887, it also effective (toggle LED) => maybe it's noise.
My hardware is using PIC 16F887, AN0 => touch button, AN1 => VCC to discharge c_hold.
Now I'm very confuse, waste many time to do this project.
P/S: I use PICKIT 2 to program code and also use power get from PICKIT2 to run my circuit => is there any noise ?
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Mon Dec 31, 2012 12:13 pm     Reply with quote

Quote:
Based on this code, I can make my application run (toggle LED each time touch), but when I touch to any A/DC input not yet be used in 16F887, it also effective (toggle LED) => maybe it's noise.
My hardware is using PIC 16F887, AN0 => touch button, AN1 => VCC to discharge c_hold.


Time to get the 'scope out and investigate.

What's connected to the other ADC pins, or are they all floating?

Mike
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