Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

pic16f876a adc to digital output function error

Status
Not open for further replies.

MarianM

New Member
Hello
I try to make a convertor from analog signal to a digital signal for my alpine mp3 car player. i found all the sequences to control the alpine, but the code generated is very long and i think memory of pic16f876a isn't enough.

a short description: i simulated in Proteus the circuit from my car command(analog), and the pic. i create in mikro C the program for pic. i used a ADC for sensing commands made and using values from conversion i make a specific function/command to alpine.

Everything seems to working ok, conversion from analog input, also the digital output is ok. But here is something tricky. instead using the "real" functions for my apline, i put some "simple" digital output sequences. If i put the real ones, the program will not build/create the hex. it tell me that is not enough memory or it will compile, but will not work after loading the hex in pic memory.

hope you understand what i try to say here. in zip are the file from simulation(alpine_sim) and the program created in mikro c(MyProject.c) and the c file with real digital output sequences for alpine(alpine.c).

at bellow address you can see from where i was inspiring :)

**broken link removed**


can anybody help me with a solution?
 

Attachments

  • alpine.rar
    58.7 KB · Views: 227
I have no idea what kind of analog commands your car sends to the alpine. And I have no idea what is the purpose of the "simple" output vs. "real" output.
But, if you are running out of memory, then get a microcontroller with more memory..
 
No idea about your code (I don't do C, so haven't looked at it) - but your requirement appears to be just a simple remote control application, similar to IR remote control (just without the 38KHz carrier. It's dead simple to do, and takes very little memory - there are assembler examples for Sony SIRC's in my tutorials, and I've used them as the basis of many different remote control types, with and without carrier.

If you're generating long code, then you're doing something badly wrong!.
 
The looped version of your code should easily fit into a 16F876. If written well it shouldn't even half fill it.

Mike.
 
I've used "simple" output just to test analog conversion and digital output and is working good. so i believe that the program is good. but, when i try to make a real command to my alpine, for example:

Vol Up 110101111101101110101011110110111101011011010101 ,(digital series of 1 and 0. A 1 is a +5V signal for 500us (500 microseconds = 0.5 milliseconds) then 0V (ground) for 500 us. What I'm calling a 0 stays at 0V for the full 1000us.)

something is happen with pic, it don't want to work. is there any way to make that output series in a simple way. now for the volume up command i use:

void f1(int cicle) //
{
while(cicle)
{
PORTB=0x08;
delay_ms(8); //
PORTB=0x00;
delay_ms(4); //
delay_us(250); //
delay_us(250); //
PORTB=0x08;
delay_us(250); // 1
delay_us(250); //
PORTB=0x00;
delay_us(250); //
delay_us(250); //
PORTB=0x08;
delay_us(250); // 1
delay_us(250); //
PORTB=0x00;
delay_us(250); //
delay_us(250); //
PORTB=0x00;
delay_us(250); // 0
delay_us(250); //
delay_us(250); //
delay_us(250); //
PORTB=0x08;
delay_us(250); // 1
delay_us(250); //
PORTB=0x00;
delay_us(250); //
delay_us(250); //
PORTB=0x00;
delay_us(250); // 0
delay_us(250); //
delay_us(250); //
delay_us(250); //
PORTB=0x08;
delay_us(250); // 1
delay_us(250); //
PORTB=0x00;
delay_us(250); //
delay_us(250); //
PORTB=0x08;
delay_us(250); // 1
delay_us(250); //
PORTB=0x00;
delay_us(250); //
delay_us(250); //
PORTB=0x08;
delay_us(250); // 1
delay_us(250); //
PORTB=0x00;
delay_us(250); //
delay_us(250); //
PORTB=0x08;
delay_us(250); // 1
delay_us(250); //
PORTB=0x00;
delay_us(250); //
delay_us(250); //
PORTB=0x08;
delay_us(250); // 1
delay_us(250); //
PORTB=0x00;
delay_us(250); //
delay_us(250); //
PORTB=0x00;
delay_us(250); // 0
delay_us(250); //
delay_us(250); //
delay_us(250); //
PORTB=0x08;
delay_us(250); // 1
delay_us(250); //
PORTB=0x00;
delay_us(250); //
delay_us(250); //
PORTB=0x08;
delay_us(250); // 1
delay_us(250); //
PORTB=0x00;
delay_us(250); //
delay_us(250); //
PORTB=0x00;
delay_us(250); // 0
delay_us(250); //
delay_us(250); //
delay_us(250); //
PORTB=0x08;
delay_us(250); // 1
delay_us(250); //
PORTB=0x00;
delay_us(250); //
delay_us(250); //
PORTB=0x08;
delay_us(250); // 1
delay_us(250); //
PORTB=0x00;
delay_us(250); //
delay_us(250); //
PORTB=0x08;
delay_us(250); // 1
delay_us(250); //
PORTB=0x00;
delay_us(250); //
delay_us(250); //
PORTB=0x00;
delay_us(250); // 0
delay_us(250); //
delay_us(250); //
delay_us(250); //
PORTB=0x08;
delay_us(250); // 1
delay_us(250); //
PORTB=0x00;
delay_us(250); //
delay_us(250); //
PORTB=0x00;
delay_us(250); // 0
delay_us(250); //
delay_us(250); //
delay_us(250); //
PORTB=0x08;
delay_us(250); // 1
delay_us(250); //
PORTB=0x00;
delay_us(250); //
delay_us(250); //
PORTB=0x00;
delay_us(250); // 0
delay_us(250); //
delay_us(250); //
delay_us(250); //
PORTB=0x08;
delay_us(250); // 1
delay_us(250); //
PORTB=0x00;
delay_us(250); //
delay_us(250); //
PORTB=0x08;
delay_us(250); // 1
delay_us(250); //
PORTB=0x00;
delay_us(250); // start part
delay_us(250); //
PORTB=0x08;
delay_us(250); // 1
delay_us(250); //
PORTB=0x00;
delay_us(250); //
delay_us(250); //
PORTB=0x08;
delay_us(250); // 1
delay_us(250); //
PORTB=0x00;
delay_us(250); //
delay_us(250); //
PORTB=0x00;
delay_us(250); // 0
delay_us(250); //
delay_us(250); //
delay_us(250); //
PORTB=0x08;
delay_us(250); // 1
delay_us(250); //
PORTB=0x00;
delay_us(250); //
delay_us(250); //
PORTB=0x08;
delay_us(250); // 1
delay_us(250); //
PORTB=0x00;
delay_us(250); //
delay_us(250); //
PORTB=0x00;
delay_us(250); // 0
delay_us(250); //
delay_us(250); //
delay_us(250); //
PORTB=0x08;
delay_us(250); // 1
delay_us(250); //
PORTB=0x00;
delay_us(250); //
delay_us(250); //
PORTB=0x08;
delay_us(250); // 1
delay_us(250); //
PORTB=0x00;
delay_us(250); //
delay_us(250); //
PORTB=0x08;
delay_us(250); // 1
delay_us(250); //
PORTB=0x00;
delay_us(250); //
delay_us(250); //
PORTB=0x08;
delay_us(250); // 1
delay_us(250); //
PORTB=0x00;
delay_us(250); //
delay_us(250); //
PORTB=0x00;
delay_us(250); // 0
delay_us(250); //
delay_us(250); //
delay_us(250); //
PORTB=0x08;
delay_us(250); // 1
delay_us(250); //
PORTB=0x00;
delay_us(250); //
delay_us(250); //
PORTB=0x00;
delay_us(250); // 0
delay_us(250); //
delay_us(250); //
delay_us(250); //
PORTB=0x08;
delay_us(250); // 1
delay_us(250); //
PORTB=0x00;
delay_us(250); //
delay_us(250); //
PORTB=0x08;
delay_us(250); // 1
delay_us(250); //
PORTB=0x00;
delay_us(250); //
delay_us(250); //
PORTB=0x00;
delay_us(250); // 0
delay_us(250); //
delay_us(250); //
delay_us(250); //
PORTB=0x08;
delay_us(250); // 1
delay_us(250); //
PORTB=0x00;
delay_us(250); //
delay_us(250); // comanda
PORTB=0x08;
delay_us(250); // 1
delay_us(250); //
PORTB=0x00;
delay_us(250); //
delay_us(250); //
PORTB=0x00;
delay_us(250); // 0
delay_us(250); //
delay_us(250); //
delay_us(250); //
PORTB=0x08;
delay_us(250); // 1
delay_us(250); //
PORTB=0x00;
delay_us(250); //
delay_us(250); //
PORTB=0x00;
delay_us(250); // 0
delay_us(250); //
delay_us(250); //
delay_us(250); //
PORTB=0x08;
delay_us(250); // 1
delay_us(250); //
PORTB=0x00;
delay_us(250); //
delay_us(250); //
PORTB=0x00;
delay_us(250); // 0
delay_us(250); //
delay_us(250); //
delay_us(250); //
PORTB=0x08;
delay_us(250); // 1
delay_us(250); //
PORTB=0x00;
delay_us(250); //
delay_us(250); //
cicle--;
}
}
//---------------------------------------------


which is very very long.

thank you and have a good day!
 
if i try to build all the program in mikro c, i get the error attached in bellow picture. also i attach all the c code for pic.
 

Attachments

  • error.jpg
    error.jpg
    197 KB · Views: 234
  • MyProject1.c
    47.9 KB · Views: 216
You need to store the data in a variable (or variables), then simply use a loop (or loops) to read the data and output it one bit at a time.

If you analyse the data you will probably find specific parts which are the same, and only need storing once - in my tutorial these are 'device' bytes (and is 0x01 for a Sony TV). You don't have entirely unique codes for every command, that would be crazy.

Check my tutorial 5.2
 
yes, i have the same series of 1's and 0's for the start and end of each command, so here are the unique parts of each:


(Start) 110101111101101110101011

Vol Up 11011011110101101
Vol Dn 01101101111101101
Mute 10101101111011101
Pst up 10101011111011110
Pst dn 01010101111111110
Source 10110111110110110
Trk up 10111011110110101
Trk dn 01011101111110101
Power 01110111111010110
Ent/Play 01010111111111010
Band/prog 01101011111101110

(End) 1010101
 
In mikroc delay_us generates in line code.
Every line with delay_us generates maybe 10 or more instructions.
You have a lot of these delays in your code, about 200/ function?
Four functions might already fill the program memory.

You should make your own delay function and call it in a command loop with a parameter.
I guess then the whole program would take a couple hundred instructions.
 
Thank you jjw for answer.

there are a lot of delays.... can you give me a little example about how to do this delay function? i'm a begginer in programming...

thank you!
 
Thank you jjw for answer.

there are a lot of delays.... can you give me a little example about how to do this delay function? i'm a begginer in programming...

You don't need to - there's already a function there - your problem (as already specified) is not using loops to send the data, you don't use linear coding like in your example it's MUCH too wasteful, and EXTREMELY poor practice. Check the assembler examples in my tutorial, or Ian's C versions at https://www.electro-tech-online.com/articles/nigel-goodwins-tutorials-in-c.467/
 
Actually you can use the delays provided by mikroc, because you have only 4 different constant delays in your program, but you must write a command function, which has as parameter the different commands like Volup etc.

This function extracts in a loop the bits from the command and sets or clears the bit in Portb and makes a delay depending of the value of the bit.
 
hello friends

i succed to resolve the problem. i've made function for 0 and for 1 and i've used this in all my program. thank you!
 
Status
Not open for further replies.

Latest threads

Back
Top