cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC 4

Anonymous
Not applicable

Hello colleagues,

   

I am trying to measure AC current with your PRoC (Eval Kit) and the Allegro's ACS712 but I can just measure noise. I am using the ADC SAR Block with 4.8Vdc as reference and very fast sampling (125ksamples per second). The ADC SAR block screenshots are attached and below is the code:

   

CY_ISR(ADC_SAR_SEQ_ISR)
{
    
    if (count == 0)
    {
        min=4096;
        max=0;
    }

   

    readValue = ADC_SAR_SEQ_GetResult16(0);    // Channel 0 is connected my pin to the ACS712 output
    
    if (readValue > max)
        max = readValue;
    if (readValue < min)
        min = readValue;
    count++;
    
    if (count >= 25000) // 0.2 seconds
    {

   

        mamp = 2.5*(max-min); // (1000*0.353*4800)/(4095*166)=2.5   // 1000 is A to mA, 0.353 is from Vpp to Vrms, 4800mV is Vref, 4095 are the bits of resolution and 166 is the mV/A given by my ACS712 
        count=0;
    }
        
}

   

The root problem is that Max and min values are always almost the same (0x5D and 0x5B), no matter which load (no load, 30mA, 200mA or 350mA) is connected. I think the ADC SAR is not really sampling so fast and that's why I measuring always the same, does any of you have an idea of what can be happening?

   

Thanks in advance,

   

Peter

0 Likes
19 Replies
Bob_Marlowe
Expert II

I am afraid that 250 thousand interrupts per second are a bit too much to handle for a PRoC. Try polling for the result. Next time can you please post your complete project, so that we all can have a look at all of your settings. To do so, use
Creator->File->Create Workspace Bundle (minimal)
and attach the resulting file.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

what do you mean by trying polling the result?

0 Likes
Bob_Marlowe
Expert II

There is an API ADC_IsEndConversion() which queries or waits for conversion ready. This will remove the overhead for handling the interrupts.

   

 

   

Bob

0 Likes
Anonymous
Not applicable
        Thanks for the kind comment. I will try but I don't think it helps solve the problem. I need to read very fast and many times the output of the current sensor in order to catch the minimum and maximum values needed for the calculations. With that API I will reduce timing but I do not think it solves my issue. Do you have an additional idea so I can try both?   
0 Likes
Bob_Marlowe
Expert II

You might use DMA to speed things up, but your selected chip might not be equipped with. Can you please post your complete project, so that we all can have a look at all of your settings. To do so, use
Creator->File->Create Workspace Bundle (minimal)
and attach the resulting file.

   

 

   

Bob

0 Likes
odissey1
Honored Contributor II
        peter, Are you trying to measure RMS of 50/60Hz main?   
0 Likes
Anonymous
Not applicable
        Yes odissey, I will upload this afternoon the whole project.   
0 Likes
Anonymous
Not applicable

Please find attached the source code. Some descriptions:

   

- Pin_Triac is to activate a Triac so the AC can get to the load.

   

- When no load connected, I can measure max=2048 and min=2047 which is expected (Half of the dynamic range, in this case 12 bits -> 4096)

   

- When connecting an AC load (i.e 250mA), the first min and max measurements are different from the 2047 and 2038 values, which results to mamp values of 80, 130, 170mA but this changes randomly and it is only the first value. The second, third and so on values are again 2047 and 2048 so something must be wrong with the sampling.

   

Do you have any idea of what can be happening?

   

Thanks in advance,

   

Peter

0 Likes
odissey1
Honored Contributor II

peter,

   

attached is working project. I tested it using KIT-044M (PSoC4200M), so you might need to re-assign pins to match P4100-BLE. You can play with ADC settings, currently input range is set to 1.024+/-1.024V (Vref=1.024 is the only real buffered reference on chip). Terminal window shows UART output changes sinchronously with input sine amplitude (from +/-0V to +/-1.024V)

   

   

   

 

   

   

0 Likes
odissey1
Honored Contributor II

Another comment: it is not good idea to measure maximum and minimum voltage for AC amplitude measurement due to the inevitable noise contribution. Standard way extracting AC amplitude from single-frequency signal (such as AC mains) is to apply a Goertzel filter algorithm, many examples of which can be found online. Despite limited hardware options in PRoC 4100, it has fast and efficient CPU, which can handle such algorithm on-the-fly.

   

http://www.embedded.com/design/configurable-systems/4024443/The-Goertzel-Algorithm

0 Likes
Anonymous
Not applicable

Hello Odissey,

   

Thanks for kind comment. I have seen you selected in the ADC Block an external trigger HW which is driven by the pin 0_0. What should I connect to that pin? If I leave it open, then I get the same results as before. If I select free running in the ADC Block, then I get no answer at all from the UART Module. Just for your information, the ACS712 Module is delivering a signal between 0-5V with AC Mains Frequency (50 or 60Hz), I don't know if this can be a problem in the ADC Block as you selected Vinternal (1.024V) as Vref...

   

Can you help me here?

   

Thanks in advance,

   

Peter

0 Likes
odissey1
Honored Contributor II

peter,

   

The ADC is set to operate in external strobe mode to limit amount of isr calls to a meaningful amount. If left free-running, minimum amount of ADC data will be about 100k/sec, which is not possible to process. For 50/60 Hz AC, having 32 points per period is enough, so the trigger clock is set to 60x32~1.9kHz.

   

In P4 clock can not drive ADC directly, so standard procedure is to pass it through a pin to convert it to digital signal. Do not connect that pin, leave it open (you may check with a scope that signal). 

   

First step would be is to run the project I supplied above and to observe it running properly with input AC signal in range 0 to 1V and offset 1.024 V and with UART output to terminal. Then modify it to suit you goals.

0 Likes
Anonymous
Not applicable

Hello odissey,

   

Thanks for the kind explanation. If I run your code just by changing the pinning to my PRoC, I get this UART output:

   

Ampl: 0  max: 2047       min: 2047
Ampl: 0  max: 2047       min: 2047
Ampl: 0  max: 2047       min: 2047
Ampl: 0  max: 2047       min: 2047
Ampl: 0  max: 2047       min: 2047
Ampl: 0  max: 2047       min: 2047

   

Are you sure your code works with the PRoC?

   

Which PSoC Creator are you using? As far as I remember my original code was working more or less fine with PSoC Creator 3.3 almost one year ago (at least it was not measuring always almost same min and max values).  

   

I also tried with a PSoC4 and the CYBL-012011 and the result is always the same. 

   

Looking forward to your feedback.

   

Peter

0 Likes
odissey1
Honored Contributor II

peter,

   

i suspect that the input pin is either not connected or fried. Try to change it to another pin. As you see from terminal window, there is small noise (~7) when sigmai is zero, but when pin is floating, then 2047 is what you will see. 

0 Likes
Anonymous
Not applicable

Odissey,

   

I changed the pin and the result is the same, min and max are always 2047. I speeded up the oscillator of the pin and the same. I have never seen those min and max changing the value. I could make some parallel measurement with the scope and a DMM. Attached you can observe a screenshot with the scope, sorry it is very old and it has a lot of noise always. I am also performing measurements with a good DMM:

   

- When Vdd in PRoC= 4.5 and no AC is connected I measure 6mVrms (AC). This is the expected noise of the ACS chip at Vdd=4.5

   

- When Vdd in PRoC= 3.3 and no AC is connected I measure 6mVrms (AC). This is the expected noise of the ACS chip at Vdd=3.3

   

- When Vdd in PRoC= 4.5 and AC load of about 130mA is connected I measure a very fix value of 18mVrms (AC). It should be a difference between min and max of about 51. Following my calculations, this would be 125mA, what is more or less ok...

   

It must be something very basic in the configuration of the ADC or even in the PRoC, do you have an idea of what can be happening with all this new information?

   

Peter

0 Likes
odissey1
Honored Contributor II
        Peter, In my project Vinp must be in range 0-2.048V, centered at 1.024V. I will refer to that project, while later you can change settings. The output of the Hall sensor is centered at 2.5V, which is outside input range. You need to scale down output about 2.5 times with a couple of resistors or pot. But first test to make sure that PRoC is alive is to short the input pin to the ground, an observe UART output going to max ~ min ~ (-2048). Other thought, can you test if PRoC's ADC is still alive by running some other program?   
0 Likes
Anonymous
Not applicable

odissey,

   

ADC is alive since I tested with the DieTemp Block and I got the temperature value correctly even when heating up and cooling down. 

   

Coming back to this project, if I follow your recommendations and scale down the output of the sensor I will lost 2.5 sensitivity, what is not the goal of the project. Why I can not use the option VDD/2? I tried with that but it is not working either. Can you maybe simulate on your side with a waveform like the ACS712 (from 2 to 3V, for example) and send me the operating code? It would be perfect,

   

Thanks in advance,

   

Peter

0 Likes
odissey1
Honored Contributor II
        Peter, I also think that the ADC is fine, you are just above 2.048V limit. To confirm, disconnect input from Hall sensor and short it to the ground, you must see min= -2047, max =-2047. If that's the case, ADC working fine, it is just that the input signal is outside the range. I will look into ADC setting, but for quick test, please change Vref from 1.024V to Vdda/2.   
0 Likes
Anonymous
Not applicable
        Odissey, Thanks for your comment. I could check that the two pins I used were fried. I changed the pin to another header of your dev kit and now it is working. I am even using vdd/2 as voltage input and I can see Ampl 20 when nothing is connected and 100 when something is connected, everything as expected. Thanks four your support, everything is fine now. Peter   
0 Likes