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.

searching for help...

Status
Not open for further replies.
i have a question, can i use P18F452 to do voice sampling?? i will have a preamp circuit, output of this will go to PIC... so, do i use ADC or PWM to convert the voice and send it through IR??

anyone pls explain a bit what actually PWM doing... thank you...
 
hhyong99 said:
i have a question, can i use P18F452 to do voice sampling?? i will have a preamp circuit, output of this will go to PIC... so, do i use ADC or PWM to convert the voice and send it through IR??

anyone pls explain a bit what actually PWM doing... thank you...

PWM is basically used to control the speed of a DC motor (or brightness of a DC fed incandescent bulb), it's an OUTPUT. The A2D could be used for sampling audio.

The problem with digitising speech is the memory space and bandwidth required, assuming you low-pass filter the audio at 3KHz or so, you need to sample it at more than twice the maximum frequency - for easy numbers we'll say 10,000 samples per second?. That's 100nS per sample, and to do it in real time you need to process and transmit that byte before the next sample is ready (100nS later) - ignoring any processing time that works out at 100,000 bits per second over the IR link, or (more likely) 200,000 bits per second if you use Manchester coding. This is a pretty fast datarate!.

Why do you want to do this?, why not just send the analogue audio over an IR link?.
 
Nigel Goodwin said:
Why do you want to do this?, why not just send the analogue audio over an IR link?.

if just send the analogue audio over an IR link, that's mean i don't have to go through PIC?? then what should i do for that?? no need programming to do the sending or what? i'm using MP2120..
 
hhyong99 said:
Nigel Goodwin said:
Why do you want to do this?, why not just send the analogue audio over an IR link?.

if just send the analogue audio over an IR link, that's mean i don't have to go through PIC?? then what should i do for that?? no need programming to do the sending or what? i'm using MP2120..

No, no need for a PIC or programming - but what's an MP2120?.

There have been many commercial IR analogue headphone systems in the past, but most now seem to have moved to RF for the link.

Moving to a digital system seems pretty pointless?, you're just using much more bandwidth and increasing difficulty and cost.
 
haha.. actually this is a school project... since i'm student, i can't just tell my lecturer that making the voice to digitize is pointless...

MP2120 is a modulator... it modulates the pulse n send to receiver

anyway, thanks Nigel... i see what i can do for now... :)
 
Nigel, i have to do voice sampling on PIC (lecturer demand)..

So, I have to use ADC for sampling, right?? Must i use interrupt in the ADC programming code?? since i just need to sample voice in PIC...

For now, i want to send in a sine wave with 1kHz into TRISA0... i'm running PIC at 20MHz...
what's the maximum voltage and current could that pin accept?
i can set which output for the ADC?
do i need Vref??
what actually "Fosc / 32" mean?
i need a timer for ADC, right?
can briefly explain ADC operation to me??

thank you very much for replying... really appreciate...
 
I am not Nigel, but maybe I can help you...

Yes ADC is required for sampilng Analog signal, you don't have to use interrupt, but it' much easier with it. You may also need stable Vref, (2.5V typical) to achieve accure measures.

You don't use TRISA for input/output (this register is for setting dirrection only!), use PORTA instead. The maximum voltage can be VDD (but it shouldn't be higher than Vref). ADC can be performed on any Analog pin (with ADC equiped PIC).
ADC needs certain timing to be met, that's why there are choices for choosing different clock dividers, you don't use TIMER0/1/2.. units
 
thanks jay...

Fosc / 32 is clock dividers?? how should i choose this?? i read the datasheet, there's acquisition time, do i need to calculate that before choosing convertion clock??
if i ADC a sine wave, the output should be in decimal number?? the output is at TX??
 
hhyong99 said:
thanks jay...

Fosc / 32 is clock dividers?? how should i choose this?? i read the datasheet, there's acquisition time, do i need to calculate that before choosing convertion clock??
Yes and Yes, this needs to be calculated, just read the datasheet carefully.

if i ADC a sine wave, the output should be in decimal number?? the output is at TX??
You have to sample the sine wave with at least 2*f sampling frequency (where f is the is the frequency of the sine wave) and the output is integer number (0-1023). This number is "inside the PIC", you need to write your own SW to output it to TX pin...
 
I would suggest you use the A2D as 8 bit, rather than the full 10, it's easy to do, and will help to maximise space and keep speed as high as possible. It's VERY!!! important to keep your sampling rate at least double the highest frequency, it's usual to use a low-pass filter to ensure higher frequencies don't get to the A2D.

As long as you keep to this sampling isn't a problem, the problem is where to store the data, and what to do with it!.

Incidently, I received this months EPE magazine today, it has a simple analogue IR voice transmitter, using a quad opamp and MOSFET in the transmitter, and a single opamp and power amp in the receiver.
 
hhyong99 said:
sorry, Nigel, but how can i set the ADC to use 8 bits instead of 10 bits??

Read my tutorial, it's simply a question of setting one bit differently, so the two lowest bits are in a seperate register, rather than the two highest bits (it's the 8 high bits you need).
 
hhyong99 said:
sorry, Nigel, but how can i set the ADC to use 8 bits instead of 10 bits??

You can't. You can select how the 10-bit result is placed in two registers. This is done by changing a bit as mentioned by Nigel in the above post.

The ADC gives 10-bit resolution and takes a certain time. You can use any number of bits of the result but the conversion will not be faster even if you do.
 
#include <p18f452.h>
#include <adc.h>
#include <delays.h>
#include <stdlib.h>
#include <usart.h>

#pragma romdata CONFIG
_CONFIG_DECL(_CONFIG1H_DEFAULT & _OSC_HS_1H,
_CONFIG2L_DEFAULT & _BOR_ON_2L & _BORV_42_2L,
_CONFIG2H_DEFAULT & _WDT_OFF_2H,
_CONFIG3H_DEFAULT,
_CONFIG4L_DEFAULT & _LVP_OFF_4L,
_CONFIG5L_DEFAULT,
_CONFIG5H_DEFAULT,
_CONFIG6L_DEFAULT,
_CONFIG6H_DEFAULT,
_CONFIG7L_DEFAULT,
_CONFIG7H_DEFAULT);
#pragma romdata

int result ;

void main(void)
{

OpenADC(ADC_FOSC_32 &
ADC_LEFT_JUST &
ADC_1ANA_2REF,
ADC_CH0 &
ADC_INT_OFF) ;

OpenUSART(USART_TX_INT_OFF &
USART_RX_INT_OFF &
USART_ASYNCH_MODE &
USART_EIGHT_BIT &
USART_CONT_RX &
USART_BRGH_HIGH, 129) ;

while(1)
{
Delay10TCYx(5) ;
ConvertADC() ;
while( BusyADC() )
;

result = ReadADC() ;

WriteUSART(result) ;
putsUSART(" ~ ") ;
while( BusyUSART() )
;
}

}



this is just a testing code for me.. i want to send in a 1kHz sine wave, A/D it and send the result to pc throught re232...
can anyone please tell me, what should be my baud rate??
will there be any problem if i convert and send to pc directly??
thank you..
 
eblc1388 said:
You can't. You can select how the 10-bit result is placed in two registers. This is done by changing a bit as mentioned by Nigel in the above post.

The ADC gives 10-bit resolution and takes a certain time. You can use any number of bits of the result but the conversion will not be faster even if you do.

The point isn't to speed the conversion, the point is to speed the processing of the result, and to reduce the amount of data you send over the wireless link. It allows you to place the result into W in a single instruction, instead of the nine required otherwise - a VERY worthwhile improvement.

hhyong99 said:
sorry, Nigel, but how can i set the ADC to use 8 bits instead of 10 bits??

From the tutorial:

ADCON1 is really a little more complicated, although it's only split into two sections. The first section is a single bit, ADFM, this is the Result Format Selection Bit, and selects if the output is Right Justified (bit set) or Left Justified (bit cleared). The advantage of this is that it makes it very easy to use as an 8 bit converter (instead of ten bit) - by clearing this bit, and reading just ADRESH, we get an 8 bit result, ignoring the two least significant bits in ADRESL.
 
if i want to set my sampling rate at 10kHz, osilloscope the result of the convertion at the one of my output pin, can that be done??
 
hhyong99 said:
if i want to set my sampling rate at 10kHz, osilloscope the result of the convertion at the one of my output pin, can that be done??

10KHz is 100uS per sample, depending on your design (mostly the source impedance feeding the A2D, as per the datasheet), this should be easily attainable. The example time calculation in the datasheet for a 16F876/7 (equation 11.1) gives a time per conversion (for the values used) of just under 20uS.

This gives you 80uS to do something with the data!.
 
Joel Rainville said:
But are you sure you want to use the C language for your PIC programming? I'm not saying it is a bad choice. It's a very good choice if you are going to work on large firmware projects, for instance.

But I'm saying there is an alternative called assembly language. MPLAB includes MPASM which will assemble (compile if you prefer) your assembly source into a hex file. And this is completely free.

Hey Joel,
I have never programmed/coded anything in my LIFE...with the exception of a few cheesy websites. I was talking with my engineer friend and he recommended that I start programming with a higher language like Basic or C. I then told him that all the "pros" on Electro-Tech recommend assembly as the foundational language.

So, if you were me and knew ABSOLUTELY NOTHING about programming...and I mean NOTHING!... how would you BEGIN to teach yourself assembly language. I've seen some different tutorials on it, but they all assume that you're somewhat familiar with programming. I don't know ANYTHING. I understand the concepts of an If/then statement, but I need to know the real deal.

What should I do? What or where would you guys go for help if you were in the same situation?
 
So, if you were me and knew ABSOLUTELY NOTHING about programming...and I mean NOTHING!... how would you BEGIN to teach yourself assembly language. I've seen some different tutorials on it, but they all assume that you're somewhat familiar with programming. I don't know ANYTHING. I understand the concepts of an If/then statement, but I need to know the real deal.

If the tutorials do not help you, you should try the datasheets, there are always examples of instructions and in some cases smaple codes are also given.

There are a few books from where you can pick up the Assembly. one of which is "Design using PIC Micocontroller" by John Peatman.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top