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

Smoke sensor operation in 8-bit mode

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



Joined: 03 Sep 2021
Posts: 39

View user's profile Send private message

Smoke sensor operation in 8-bit mode
PostPosted: Sat Feb 12, 2022 4:50 am     Reply with quote

Hello
I'm setting up a smoke sensor -MQ2.
Which I had previously launched it with the micro pic16f1939.
My module is a mq2 and only has its own sensor and has no additional board.
I made the connection according to the datasheet and the previous process with pic 16f1939.
But the problem is that it always shows the number 255, while the voltage is below 0.1 volts, and when the voltage increases, the analog voltage reaches 2 volts, but the sensor still has a maximum of 255.
I am using pic16f723a which has an 8 bit Adc.
I will put the sample code below:
Code:

#include <16f723A.h>                                                                     
#fuses PROTECT,NOWDT,NOMCLR,NOBROWNOUT,PUT                                               
#device ADC=8 
#use delay(internal=8000000)   
int8 adc1;       
#USE STANDARD_IO (a)
#USE STANDARD_IO (b)
#USE STANDARD_IO (c)

void main()
{
setup_adc(ADC_CLOCK_DIV_64);
setup_adc_ports(sAN4|sAN13);   
while (1)
 {
  set_adc_channel(4);                                                         
   delay_us(10)       ;
   adc1 =read_adc()
   IF (adc1>200) output_high  (power_led) ;
   IF (adc1>250) output_high  (up_led)    ;
   if (adc1>255)                                         
   {
    output_high  (down_led);     
    output_low(buzzer);                                                                                         
   }
 }
}



Is there anything suspicious?
I myself doubted the reference voltage, but the micro does not allow writing code.
Code:
setup_vref (VREF_ADC_1v024);
setup_adc_ports (sAN7 | sAN9, VREF_FVR);
temtronic



Joined: 01 Jul 2010
Posts: 9221
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Feb 12, 2022 6:46 am     Reply with quote

quick comments.

#fuses PROTECT,NOWDT,NOMCLR,NOBROWNOUT,PUT
remove the PROTECT fuse, NOT needed, until product goes to customer. NOT needed for 'home' use.

setup_adc(ADC_CLOCK_DIV_64);

wrong clock divider, use div_8
There's a chart, Table 15-1 that shows the proper clock vs adc configurations
while div-16 and div-32 are good, div-8 is the fastest.

FVR is the Fixed Voltage Reference, cannot be used as the ADC voltage reference. The ADC Vref is either VDD or an external precision voltage reference device.
Since you're using 8 bit ADC mode, simply use VDD as Vref.
Ttelmah



Joined: 11 Mar 2010
Posts: 19496

View user's profile Send private message

PostPosted: Sat Feb 12, 2022 7:18 am     Reply with quote

ADC1 is an 8bit value. The adc itself only returns an 8bit value. An 8bit value
can only hold 0 to 255. Hence can never be >255....
Sounds like this code may be what was being used with the ADC set
to ADC=10?.

The output voltage you get from the sensor will depend on the resistance
you have across the PIC input. The sensor needs a 5v supply to it's heater,,
and a separate supply to the sensor, with a load resistor. This should be
between 2K2 and 20KR. Without a load resistor the output will be always
5v (assuming 5v is fed to the sensor).

One other thing. You have looked really carefully at 'where' AN4 actually
is?. Key is that PortA4, does not have an analog connection. AN4 is
PortA5. Where is Vcap connected?. On these chips you need s smoothing
capacitor on one of the Vcap pins, and this has to be specified in the
fuses. You do not show a fuse for this.... The chip will not run properly
without Vcap and the voltage regulator pin selected. Understand the 'core'
of this chip runs at 3.6v. It needs the regulator to give this. The alternative
'LF' chip does not have the regulator and runs directly at 3.6v.
GiG



Joined: 03 Sep 2021
Posts: 39

View user's profile Send private message

PostPosted: Sat Feb 19, 2022 11:39 pm     Reply with quote

Thank you for your accurate and professional answers.
The problem was solved with that Resistance mentioned and the analog pin check.
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