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

Communication rf adc
Goto page 1, 2, 3, 4  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
sergio3214



Joined: 15 Mar 2017
Posts: 25
Location: brasil

View user's profile Send private message

Communication rf adc
PostPosted: Wed Mar 22, 2017 3:58 pm     Reply with quote

Good night from brazil
I am Sergio Oliveira.
I would like your help.
I want to make rf communication with adc converter.
So that the transmitter makes analog reading and sends it to the receiver. I have done an rf code and it works but the analog conversion of one pic and sending to the other does not work.
Ttelmah



Joined: 11 Mar 2010
Posts: 19219

View user's profile Send private message

PostPosted: Thu Mar 23, 2017 1:45 am     Reply with quote

Seriously, talk about zero data....

There is no 'standard' way of sending RF. Every design of RF modules has different settings needed.

What PIC?.
What compiler version?.
What RF modules?.

If you have the cheap RF modules like the RF12B, these require the data sent to be encoded so the number of 1's and 0's sent is kept balanced (the standard way of doing this is a system called 'Manchester encoding'). If your modules need this, then search here for code, but also 'think again'. It is a lot of work.
There are much easier modules to drive like:
<http://www.rfsolutions.co.uk/acatalog/info_SMARTALPHA_433.html>
These can just accept data without such encoding.
temtronic



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

View user's profile Send private message

PostPosted: Thu Mar 23, 2017 4:56 am     Reply with quote

Another choice of RF modules would be the HC-12. $6,good for 3/4Km,simple serial interface,3 and 5 volt capable.

Jay
sergio3214



Joined: 15 Mar 2017
Posts: 25
Location: brasil

View user's profile Send private message

Communication rf adc
PostPosted: Thu Mar 23, 2017 1:33 pm     Reply with quote

Good afternoon I'll introduce the code I'm trying to create.
I have already done the LEDs but what I want now is to make the ADC communication from one pic to another so that one is the transmitter and another the receiver.
Code:

 transmitter
#include <12f675.h>
# DEVICE ADC=8

#fuses INTRC_IO,NOWDT,NOPROTECT, NOMCLR ,BROWNOUT, PUT
#use delay(clock=4000000)       // 4 MHz crystal on PCB
//#use rs232(baud=19200, xmit=PIN_A0, rcv=PIN_A1)    // you can use any pins for software uart...
#use rs232(baud=9600, xmit=PIN_A4, rcv=PIN_A2, PARITY=N, BITS=8,)

// characters transmitted faster than the pic eats them will cause UART to hang.

#include <stdlib.h>

#define LED_5 PIN_A5
#define LED_1 PIN_A1
#define ciclo_3 PIN_3
#define TX_4 PIN_A4
#define RX_2 PIN_A2

#define fim 100

int8 periodo=0;
int8 ciclo1=0;

#int_timer1
void Timer_isr(void)
{
   /*=====================
   Teste para ciclo = 0
   =====================*/
   
   if(ciclo1 == 0)
   {
      output_low (PIN_A3);
   }
   if(ciclo1 == fim)
   {
      output_high(PIN_A3);
   }
   
   
   /*=============================
   Já que o ciclo e diferente de 0
   ===============================*/
   
   if(periodo < ciclo1)
   {
      output_high(PIN_A2);
   }
   else
   {
      output_low(PIN_A2);
   }
   if(periodo >= fim-1)
   {
      periodo=0;
   }
   periodo++;
   set_timer1(65440);   //65440
}

void setup ()
{
   SETUP_ADC_PORTS(sAN0);
   SETUP_ADC(ADC_CLOCK_DIV_8);
   
   SETUP_TIMER_1 (T1_INTERNAL|T1_DIV_BY_1);    // Configurar timer1 para clock interno/8
   enable_interrupts (INT_TIMER1);             // Habilitar Interrupções
   enable_interrupts (GLOBAL);
   set_timer1(65440);                          // Preload do timer1
   
   set_adc_channel(0);
   delay_ms(20);
   
   
 
   
   while(TRUE)
   {
      ciclo1 = 0.4 * read_adc();
      delay_ms (50);
   }
}

void main (DADOS) {
   while (TRUE) {
      if (input(PIN_A5)){
         output_high(LED_5);
         printf("a"); //sends signal a
         delay_ms(1000);
         
       }
       else{
         output_low(LED_5);
         printf("l"); //sends signal l
         delay_ms(200);
         
       }
        if (input(PIN_A1)){
           output_high(LED_1);
           printf("b"); //sends signal b
           delay_ms(1500);
        }
        else{
           output_low(LED_1);
           printf("s"); //sends signal s
           delay_ms(500);
        }   
       }
       
   }
   
Receiver

#include <12F675.h>
#DEVICE ADC=8
#fuses INTRC_IO,NOWDT,NOPROTECT, NOMCLR ,BROWNOUT, PUT       
#use delay(clock=4000000)       // 4 MHz crystal on PCB
//#use rs232(baud=19200, xmit=PIN_A0, rcv=PIN_A1)    // you can use any pins for software uart...
#use rs232(baud=9600, xmit=PIN_A4, rcv=PIN_A2, PARITY=N, BITS=8,)
// characters transmitted faster than the pic eats them will cause UART to hang.

#define LED_0 PIN_A0
#define LED_1 PIN_A1
#define Tx_4  PIN_A4
#define RX_2  PIN_A2
#include <stdlib.h>

char x;

void main(DADOS) {
   while (TRUE) {
       if (kbhit()) {
         x = getc();
       }
       if (x=='a'){
         output_high(LED_0);
         
       }
       else{
         output_low(LED_0);
         
       }
       if (x=='b') {
          output_high(LED_1);
       }
       
       else{
          output_low(LED_1);
       }
   }
}

People help I want to mutate the ADC conversion from one pic to another.
Ttelmah



Joined: 11 Mar 2010
Posts: 19219

View user's profile Send private message

PostPosted: Thu Mar 23, 2017 3:38 pm     Reply with quote

Switch to PIC's that have a UART.

Big problem is that the chips you are trying to use don't have a UART. This gives you no flexibility at all in the receiving chip. It _has_ to be sitting 'waiting' for a character to arrive, or it'll miss it.
If you must use a tiny PIC, use something like the 1822, or 1840.
sergio3214



Joined: 15 Mar 2017
Posts: 25
Location: brasil

View user's profile Send private message

PostPosted: Thu Mar 23, 2017 6:29 pm     Reply with quote

The problem of me uses this pic that I quote in reference and that here in Brazil I can not find it.
But who can help me in this code I thank.
Ttelmah



Joined: 11 Mar 2010
Posts: 19219

View user's profile Send private message

PostPosted: Fri Mar 24, 2017 1:55 am     Reply with quote

So far you have not told us anything about 'the code'. Except that you want to move the ADC to the other chip.

Problem is that doing so, implies data will have to go both ways on your comm link. Now you still haven't told us the radio modules involved?. Almost certainly the radio is half duplex (one way at a time only). However worse, the PIC without a UART, to receive has to be sitting 'waiting' to receive. Going off to do other things (like handling the ADC), starts to become complex programming. A lot also depends on how quickly the link needs to send things. So (for instance), treat one chip as the 'master' (possibly the current transmitter), and when it wants an ADC reading from the other end, have it send a request for the reading. Have the other end stop listening, then take a reading and reply. This way the 'master' chip can after sending the request, start listening, and the slave can stop listening, read the ADC, send the reply & switch back to listening. (Ideally add a checksum to the reply so you 'know' it has transmitted correctly).

However the code is going to start to get a lot larger. Probably unlikely to fit in the 675 (especially when you do silly things like multiplying by 0.4.. Search here on why you do not use float, and think about much faster/easier ways of doing this) (hint int16 *102, then just use the top byte).

Part of programming is learning to actually 'think out' the problem. So far you are not describing it fully to us, which may well mean you have really not got what has to happen clear in your own mind. We can't help till you do....

It's a bit like a person trying to drive a car, saying to their instructor "I'm having problems". The instructor then has to ask loads of questions, and eventually find the problem is with the clutch and gear changing. Without knowing what the problem actually 'is' they would waste ages on steering, braking etc..
You need to be asking the questions of yourself.
sergio3214



Joined: 15 Mar 2017
Posts: 25
Location: brasil

View user's profile Send private message

PostPosted: Fri Mar 24, 2017 9:46 am     Reply with quote

Code:
#include <12f675.h>
#DEVICE ADC=8

#fuses INTRC_IO,NOWDT,NOPROTECT, NOMCLR ,BROWNOUT, PUT
#use delay(clock=4000000)  // 4 MHz crystal on PCB
//#use rs232(baud=19200, xmit=PIN_A0, rcv=PIN_A1)    // you can use any pins for software uart..
#use rs232(baud=9600, xmit=PIN_A4, rcv=PIN_A2,STREAM=Wireless )
// characters transmitted faster than the pic eats them will cause UART to hang.

#include <stdlib.h>
#define ADC_0 PIN_A0
#define RS232_TX_PIN PIN_A4
#define RS232_RX_PIN PIN_A2
#define VALOR_v PIN_A5
int8 c;
int8 valor_alto;
int8 valor_baixo;

void main()
{   
   setup_adc_ports(sAN0);                             
   setup_adc(ADC_CLOCK_DIV_8);
   
   set_adc_channel(0);
   delay_us(20);
   
   while(1)
   {
     
      {                     
         valor_alto = (read_adc()>>8);
         fprintf(Wireless,"%c", valor_alto);
         delay_ms(100);
         valor_baixo = (int)(read_adc());         
         fprintf(Wireless,"%c", valor_baixo);
         
      }
   }   
}

Receiver:
Code:

#include <12f675.h>
#fuses INTRC_IO,NOWDT,NOPROTECT, NOMCLR ,BROWNOUT, PUT
#use delay(clock=4000000)  // 4 MHz crystal on PCB
//#use rs232(baud=19200, xmit=PIN_A0, rcv=PIN_A1)    // you can use any pins for software uart..
#use rs232(baud=9600, xmit=PIN_A4, rcv=PIN_A2,Errors,STREAM=Wireless )
// characters transmitted faster than the pic eats them will cause UART to hang.

#include <stdlib.h>
#define LED_0 PIN_A0
#define RS232_TX_PIN PIN_A4
#define RS232_RX_PIN PIN_A2
#define LED_5 PIN_A5

int8 n;
int8 vetor[3];
int16 resultado;
int1 data;
int8 termo_1;
int8 termo_2;
int16 resultado_1;


void RDA_isr(void)
{
   vetor[n] = getc();
   if (n == 1);{output_low(LED_5);}
   {
      data = 1;
      n = 0;
   }
   n++;
   
}

void main()

 
   
   enable_interrupts(global);
   while(TRUE)
   { 
      if (data == 1); {
     
      }
     
      {           
         resultado = (((int16)vetor[0]<<8) | vetor[1]);         
         fprintf (Wireless, "\n\r%lu", resultado);         
         data++;
      }
   }
}


Here is my new code, can you tell me now what is the error ? The conversion is working for not the signal reception, and the modules that I will use would be the HC-12.
jeremiah



Joined: 20 Jul 2010
Posts: 1317

View user's profile Send private message

PostPosted: Fri Mar 24, 2017 10:09 am     Reply with quote

I can't see datasheets here, but did you address Ttelmah's comment about needing a hardware UART? If not, your interrupt won't fire.

Also, you haven't told the compiler your ISR is an interrupt handler, so you need to use the appropriate precompiler directive (SEE #INT_ in the compiler manual)
sergio3214



Joined: 15 Mar 2017
Posts: 25
Location: brasil

View user's profile Send private message

PostPosted: Fri Mar 24, 2017 10:19 am     Reply with quote

Has passed an example of how I should correct the code, I already thank you.
sergio3214



Joined: 15 Mar 2017
Posts: 25
Location: brasil

View user's profile Send private message

PostPosted: Fri Mar 24, 2017 2:24 pm     Reply with quote

Code:
//transmit coding

#include <12f675.h>
#DEVICE ADC=8

#fuses INTRC_IO,NOWDT,NOPROTECT, NOMCLR ,BROWNOUT, PUT
#use delay(clock=4000000) 
#use rs232(baud=9600, xmit=PIN_A4, rcv=PIN_A2,STREAM=Wireless )

#include <stdlib.h>
#define ADC_0 PIN_A0
#define RS232_TX_PIN PIN_A4
#define RS232_RX_PIN PIN_A2
#define VALOR_V PIN_A5
int8 c;
int8 valor_alto;
int8 valor_baixo;

void main()
{   
   setup_adc_ports(sAN0);                             
   setup_adc(ADC_CLOCK_DIV_8);
   
   set_adc_channel(0);
   delay_us(90);
   
   while(1)
   {
     
      {                     
         valor_alto = (read_adc()>>8);
         fprintf(Wireless,"%c", valor_alto);
         delay_ms(100);
         valor_baixo = (int)(read_adc());         
         fprintf(Wireless,"%c", valor_baixo);
         
      }
   }   
}

receiver
Code:

#include <16F877A.h>

#define WireTX PIN_c6
#define WireRX PIN_c7
#define Nivel alto PIN_c0
#define Nivel baixo PIN_C0
#FUSES XT
#FUSES NOWDT   
#FUSES PUT         
#FUSES NOPROTECT     

#use delay(clock=4000000) 

#use rs232(baud=9600, xmit=WireTX, rcv=WireRX, ERRORS, STREAM=Wireless)

int8 n;
int8 vetor;
int1 data;

#int_RDA
void RDA_isr(void)
{
   vetor = getc();   
   n++;
   if (n == 1)   
       
         
       
      {
      data = 1;
      n = 0;
   }
}

void main()
{
   enable_interrupts(INT_RDA);

   enable_interrupts(global);

   While (TRUE)
   {
      if (data == 1)
           
      {                     
         fprintf (Wireless, "\n\r%u", vetor);         
         data++;
      }
     
   }
}

What's wrong with this code, can anyone help me?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Mar 24, 2017 5:32 pm     Reply with quote

sergio3214 wrote:

//transmit coding

#include <12f675.h>
#DEVICE ADC=8
void main()
{
valor_alto = (read_adc() >>8);

}

Read the CCS manual about how the read_adc() function works.
You have told the compiler to give you a single byte (8 bits) with the
#device statement. So you should write:
Code:
valor_alto = read_adc();
sergio3214



Joined: 15 Mar 2017
Posts: 25
Location: brasil

View user's profile Send private message

PostPosted: Fri Mar 24, 2017 7:20 pm     Reply with quote

Now how do I to send to a pin with the high and low value on the receiver through the conversion adc of the transmitter ?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Mar 24, 2017 8:21 pm     Reply with quote

If you want a 10-bit ADC result, you must tell the compiler that you
want it, by using a #device statement. Example:
Code:
#include <12f675.h>
#device ADC=10

You can only get 10 bits. This is stated in the 12F675 data sheet.
Do not attempt to get 16-bits with the #device statement. It will not work.
You can only get 10-bits maximum from the ADC.

How to do it ?
First you must read the 10-bit adc result into a 16-bit variable.
Then you must send the MSB, and then the LSB. Example:
Code:

int16 adc_result;

adc_result = read_adc();       // Read 10-bit adc result
valor_alto = adc_result >>8;   // Get MSB of adc result
fprintf(Wireless,"%c", valor_alto);
delay_ms(100);                       
valor_baixo = (int8)adc_result;  // Get LSB of adc result       
fprintf(Wireless,"%c", valor_baixo);
sergio3214



Joined: 15 Mar 2017
Posts: 25
Location: brasil

View user's profile Send private message

COMUNICAÇÃO rf adc
PostPosted: Sat Mar 25, 2017 2:29 pm     Reply with quote

PCM programmer Good afternoon I did what you told me the conversion happens, but the output pin on the transmitter is not set yet, as I'm going to do so that when the transmitter sends the high value to the receiver it is set in the transmitter with a high value in the transmitter. EX PIN_B0, because I have the answer on the receiver but on the TX pin of the receiver, I THANK YOU FOR THIS HELP IF I'M HAPPY FOR THIS
Code:


//transmit coding

#include <12f675.h>
#DEVICE ADC=10

#fuses INTRC_IO,NOWDT,NOPROTECT, NOMCLR ,BROWNOUT, PUT
#use delay(clock=4000000) 
#use rs232(baud=2400, xmit=PIN_A4, rcv=PIN_A2,STREAM=Wireless )

#include <stdlib.h>
#define ADC_0 PIN_A0
#define RS232_TX_PIN PIN_A4
#define RS232_RX_PIN PIN_A2
#define VALOR_V PIN_A5
int8 c;
int8 valor_alto;
int8 valor_baixo;

void main()
{   
   setup_adc_ports(sAN0|sAN1);                             
   setup_adc(ADC_CLOCK_DIV_8);
   
   set_adc_channel(0);
   delay_us(20);
   
   while(1)
   {
     
      {                     
         int16 adc_result;

             adc_result = read_adc();       // Read 10-bit adc result
             valor_alto = adc_result >>8;   // Get MSB of adc result
             fprintf(Wireless,"%c", valor_alto);
             delay_ms(100);                       
             valor_baixo = (int8)adc_result;  // Get LSB of adc result       
             fprintf(Wireless,"%c", valor_baixo);
      }
   }   
}

receiver
Code:

#include <16F877A.h>

#define WireTX PIN_c6
#define WireRX PIN_c7

#FUSES XT
#FUSES NOWDT   
#FUSES PUT         
#FUSES NOPROTECT     

#use delay(clock=4000000)                 

#use rs232(baud=2400, xmit=WireTX, rcv=WireRX, ERRORS, STREAM=Wireless)

int8 n;
int8 vetor[3];
int16 resultado;
int1 data;
int8 termo_1;
int8 termo_2;
int16 resultado_1;

#int_RDA
void RDA_isr(void)
{
   vetor[n] = getc();
   if (n == 1)
   {
      data = 1;
      n = 0;
   }
   n++;
   
}

void main()

   enable_interrupts(INT_RDA);
   
   enable_interrupts(global);
   while(TRUE)
   { 
      if (data == 1)
      {           
         resultado = (((int16)vetor[0]<<8) | vetor[1]);         
         fprintf (Wireless, "\n\r%lu", resultado);         
         data++;
      }
   }
}
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2, 3, 4  Next
Page 1 of 4

 
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