Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[???] Which MCU should I use to convert signal?

Status
Not open for further replies.
Hi,

The 1N4148 is in wrong direction.
Use a 1k resistor in series with the 1N4148.
Use a 4V7 zener and a 100k jn parallel to it.

Klaus
 

If I dont have 4.7V Zener diode, can I use 3.3V one?

Is this correct now:
1885186300_1462770440.png
 

Hi,

to answer your question I need to read both datasheets: microcontroller and zener.

so it´s best you check the datasheets:
microcontroller: Look for V_IH. Maximum port pin input voltag to detect HIGH signal
zener: chart: min voltage at 100uA.

If zener voltage is higher then you are on the safe side.

Klaus
 

Okay, but how am I supposed to read this:


My VDD is 5V so it's simply 2V?

So: 2.1 V at pin means HIGH and 1.9V at pin means LOW?

But waaaaaaait.... I was going to use ADC to detect the sine rise...
Does it makes sense to check TTL voltage levels while I want to use ADC?
 

Hi,

But waaaaaaait.... I was going to use ADC to detect the sine rise...
Does it makes sense to check TTL voltage levels while I want to use ADC?

You are correct. I forgot you use ADC... My mistake.

*****
Logic input levels:
My VDD is 5V so it's simply 2V?
Yes. Every input signal >2.0V means HIGH.
and 1.9V at pin means LOW?
No! You have to look for V_IL to know what the valid levels for LOW are.
Usually the limit is at about 0.7V. Everything below is LOW.

Input voltages 0.7V .... 2.0V are not valid! The input value (HIGH/LOW) is unknown. Avoid these levels. They may cause problems. (Oscillations, EMI, increased current consumtion)

Klaus

- - - Updated - - -

ADDED:
BTW. I don´t recommend using ADC. It is slow compared to logic levels or comparator input. But if this is no problem for your application then for sure you may use it.

Klaus
 

If I dont have 4.7V Zener diode, can I use 3.3V one?

You can build up to a desired voltage by adding ordinary diodes in series with the 3.3V zener. Add 0.6V or so, per diode.

You can also use led's. 1.7V with a red type, higher voltage with other colors.
 

ADDED:
BTW. I don´t recommend using ADC. It is slow compared to logic levels or comparator input. But if this is no problem for your application then for sure you may use it.

Klaus




Ok Ok, thanks for generic information.
So you say it would be better to use digital input?
But wait... I need to detect the sine rise precisely. I can't wait until sine reaches 5V or so....
So I tought that ADC is the way to go...
What else do you suggest?
I have PIC16F628A at hand.

And I bought 4.7 Zener Diodes.
 

Hi,

I need to detect the sine rise precisely
Precision...
An ADC has good voltage resolution. A logic input is very fast, this is precision, too.
To get absolute precision you need to take care about both.

I don't know what sample frequency you consider to use. Let's say 10kSamples/s.
And let's assume the input signal is 50Hz, pure sine with an amplitude of 3V.
Then at zero cross yo get abot 470V/s.
With a sample ratd of 10kHz you have an uncertainty of 100us. In voltage this means 47mV.

Because a logic input has a threshold level of about 2V it is worse than the ADC

But with the comparator you may adjust the threshold level.
To set it below 47mV is easily possible.
But because a comparator has no fixed sample frequency (like grid) it does not have the huge uncertainty in timing.
A comparator may have an uncertainty below 1us. (Use interrupt driven signal detection.)

Therefore i expect way less jitter when you use a comparator.

Klaus
 

I have made a test with ADC of PIC18F2550.

It is supposed to detect a sine upper half and write to uart and change led state.

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#define ADC_TEST_VALUE 100
 
void main() {
int ac, pot;
  OSCCON = 0b01110010; // Set internal clock on 8MHz
  TRISA = 0;           // set direction to be output
  TRISB = 0;           // set direction to be output
 
     ADCON1 = 0x00;                           //configure all pins as analog, pins are not disabled individually
//  UART1_Init(9600);               // Initialize UART module at 9600 bps
 
 
  do {
    LATA = 0x00;       // Turn OFF LEDs on PORTA
    LATB = 0x00;       // Turn OFF LEDs on PORTB
    ac = ADC_Read(2);
    if(ac < ADC_TEST_VALUE)
          continue;
    LATA = 0xFF;       // Turn ON LEDs on PORTA
    LATB = 0xFF;       // Turn ON LEDs on PORTB
 
    // stay on until sine goes down
     while(1)
     {
             ac = ADC_Read(2);
             if(ac < ADC_TEST_VALUE)
                  break;
 
    }
   // UART_Write_Text("Changed");
  } while(1);          // Endless loop
}



It works when I manually connect ADC directly to GND and then to VCC (it detects a change).

but it does not work with AC signal.
This is strange.
Also, when I oscilloscope the AC signal at the ADC pin it's flat! It's only correct when I disconnect the ADC pin (I can clearly see the upper half wave of sine, which upper part is also cut of by zener diode).

What is wrong?
 

Hi,

For me it sounds like there is a capacitor connected to the ADC pin.

But maybe you did not set up the ADC pin correctely. It needs to be high impedance input. Disable pullup.

Klaus
 

Where, in the code in Post #30, are you configuring and turning on the ADC. All I can see is you setting ADCON1 but there is no reference to ADCON0 (which is needed if only to turn on the ADC) and ADCON2.
I do not know which ANx port you are reading (does the reference to '2' mean AN2 or is it a bitmap of the analog ports to read in which case it would be AN1). In either case AN1 and AN2 share pins with PORTA which you are driving as digital outputs which will also drive the ADC to read as the minimum ('0') or maximum ('1') voltage.
Susan
 

I think I have found the reason.
I had my PIC18F2550 damaged before.
I accidentally connected the AC signal in wrong place.
First I wanted to replace it, but the programmer worked with that PIC.
I have also tested if it recognizes the GND and VCC at levels at ADC and it also worked.
But PIC is taking around 600mA at idle and new PIC is taking 0.02A !!

So, I will test again right now with the new PIC.
Aussie - ADC_Read(0) is the first analog port (AN0), ADC_Read(1) is AN1 and so on.
But maybe you are right...

EDIT: I have checked ADC_Read with 0, 1, 2, 3 and it seems it works okay with potentiomenter, I am going to conenct AC signal now, we will see if it works.

EDIT: Still the same issue, the signal goes flat when I connect it to the ADC.... but Zener diode works and I can clearly see it.
 
Last edited:

Hi,

it seems you control the ADC just in the main loop without known/fixed timing.

I strongly recommend to use a fixed ADC sampling rate and an interrupt driven processing of the ADC values.

Klaus
 

Hi,

it seems you control the ADC just in the main loop without known/fixed timing.

I strongly recommend to use a fixed ADC sampling rate and an interrupt driven processing of the ADC values.

Klaus


What do you mean? My code works when I test it with potentiometer (it switches LED state).
It is supposed to do the same with AC signal, just very fast, but I will see it with osciloscope.

I am starting to think that the Zener Diode, diode and two resistors schematic from some posts before is not working as it should... but osciloscope is showing correct wave when I disconnect ADC pin.
 


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#define ADC_TEST_VALUE 100
 
void main() {
int ac, pot;
  OSCCON = 0b01110010; // Set internal clock on 8MHz
  TRISA = 0;           // set direction to be output
  TRISB = 0;           // set direction to be output
 
     ADCON1 = 0x00;                           //configure all pins as analog, pins are not disabled individually
//  UART1_Init(9600);               // Initialize UART module at 9600 bps
 
 
  do {
    LATA = 0x00;       // Turn OFF LEDs on PORTA
    LATB = 0x00;       // Turn OFF LEDs on PORTB
    ac = ADC_Read(2);
    if(ac < ADC_TEST_VALUE)
          continue;
    LATA = 0xFF;       // Turn ON LEDs on PORTA
    LATB = 0xFF;       // Turn ON LEDs on PORTB
 
    // stay on until sine goes down
     while(1)
     {
             ac = ADC_Read(2);
             if(ac < ADC_TEST_VALUE)
                  break;
 
    }
   // UART_Write_Text("Changed");
  } while(1);          // Endless loop
}


I have improved the code. It seems it works now.
I have added:

Code C - [expand]
1
ADC_Init();


I have removed:


Code C - [expand]
1
LATA = 0x00;       // Turn OFF LEDs on PORTA


and


Code C - [expand]
1
LATA = 0xFF;       // Turn ON LEDs on PORTA



I don't know which change really fixed it, but now ADC seems to be really working.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top