• AVR Freaks

AnsweredHot!Op Amp / Comparator Block: issue setting the voltage reference (DAC)

Author
FilippoMonti
Starting Member
  • Total Posts : 31
  • Reward points : 0
  • Joined: 2017/11/03 03:10:15
  • Location: 0
  • Status: offline
2019/06/19 06:14:24 (permalink)
0

Op Amp / Comparator Block: issue setting the voltage reference (DAC)

Dear Lubin,
 
I have another small issue with the Comparator block.
 
I have three shunt resistors that measure the current. I have connected these three signals to the negative input of the comparators, while the positive input is the voltage reference. When there is excessive current, the output goes low and activate a fault signal that turns down the PWM (and activate some error LEDs).
All works with fixed voltage reference. But, I have noticed that the comparators do not have hysteresis, so that I want to create manually the hysteresis by changing the reference through the DAC input of the blockset (see images).
 
When the comparator out goes low, I switch the reference to a lower level and vice versa.
I cannot find a way to get it working. Whenever I manage externally through the DAC the voltage reference, the comparators does not work properly. Even with a fixed DAC input.
I have also monitored the thing on the CVref1O pin.
All work if DAC input is disabled and the voltage reference is set inside the blockset. The output on this pin is =0V whenever I activate the DAC input of the block.
 
Can you help me? How does it work this function?
The test model is attached.

Thank you very much
 
Filippo

Attached Image(s)

#1
Lubin
Moderator
  • Total Posts : 360
  • Reward points : 5
  • Joined: 2007/03/31 07:38:15
  • Location: Bayonne, France
  • Status: offline
Re: Op Amp / Comparator Block: issue setting the voltage reference (DAC) 2019/06/19 06:40:53 (permalink)
0
Hi Filippo,
 
Just one check before investigating: the DAC input is an integer where the LSB code for 0.138V on the DAC as mentionned in the DAC block : "block input (4 bits) cpde for 0.138V Steps within interval [0V  2.1V]".
 
Values 1 and 2 will code respectively for 0.138V and 0.276V. It is not 1V an 2V.  Is this change large enough for your test ? for 1V and 2V, you might use values 7 (0.96V) and 14 (1.93V)
 
Lubin
#2
Lubin
Moderator
  • Total Posts : 360
  • Reward points : 5
  • Joined: 2007/03/31 07:38:15
  • Location: Bayonne, France
  • Status: offline
Re: Op Amp / Comparator Block: issue setting the voltage reference (DAC) 2019/06/19 07:02:33 (permalink)
0
Filippo,
 
I find a typo in the code generation script for this DAC block for some dsPIC affecting the current blockset release.
The DAC input might not be taken into account (value is initialized to 0 and kept at 0).
 
It's fixed. Solution is to be published shortly.
 
Lubin
#3
Lubin
Moderator
  • Total Posts : 360
  • Reward points : 5
  • Joined: 2007/03/31 07:38:15
  • Location: Bayonne, France
  • Status: offline
Re: Op Amp / Comparator Block: issue setting the voltage reference (DAC) 2019/06/20 06:31:00 (permalink) ☼ Best Answerby FilippoMonti 2019/06/30 22:39:34
0
Hi Filippo,
 
Here is a temporary link with the next release.
Installer is likely to change using matlab package format.
 
https://fr.mathworks.com/matlabcentral/fileexchange/71892-mplab-device-blocks-for-simulink
 
Please download this file.
within matlab:
1) type picclean to clean matlab path from current release
2) Run this mtlbx package (just open the file from matlab)
3) type picsetup, or restart matlab to force matlab path update.
 
Edit: provide official link to v3.45 blockset
post edited by Lubin - 2019/06/28 03:34:31
#4
FilippoMonti
Starting Member
  • Total Posts : 31
  • Reward points : 0
  • Joined: 2017/11/03 03:10:15
  • Location: 0
  • Status: offline
Re: Op Amp / Comparator Block: issue setting the voltage reference (DAC) 2019/06/21 06:34:58 (permalink)
0
Dear Lubin,
 
thank you very very much :)
Unfortunately I do not have the possibility to test it until monday. Then I will post here, also for the other forum's people, my experience with this comparator hysteresis settings :)
 
BTW, I will have to use the threshold 0.276V because I have used very small shunt resistors of 0.033Ohm. So that the maximum hysteresis I can get is between 0.276V and 0.138V. But, for test purposes I will try also your suggested 0.96V - 1.93V.
 
I will let you know on Monday. Thank you
 
Filippo
 
#5
FilippoMonti
Starting Member
  • Total Posts : 31
  • Reward points : 0
  • Joined: 2017/11/03 03:10:15
  • Location: 0
  • Status: offline
Re: Op Amp / Comparator Block: issue setting the voltage reference (DAC) 2019/06/30 22:39:11 (permalink)
0
Dear Lubin,
 
I have tested the new release and now the DAC works. Thank you :)
 
I have a small issue again though.
If I set a voltage V>threshold, the comparator react as expected (i.e. its output goes low). Then, if I turn off the dsPIC but I keep that voltage on the input of the comparator, when I re-turn on the dsPIC, the comparator does not react and its output is high.
Only if I go down below the threshold with the voltage and then I go up again, then it starts to react properly.
 
Is it a "normal" situation because of the internal construction/manage of the comparator of the dsPIC? Or is it something in the SW?
 
Thank you.
 
Filippo
#6
ric
Super Member
  • Total Posts : 22715
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: offline
Re: Op Amp / Comparator Block: issue setting the voltage reference (DAC) 2019/06/30 22:51:45 (permalink)
0
FilippoMonti
...
If I set a voltage V>threshold, the comparator react as expected (i.e. its output goes low). Then, if I turn off the dsPIC but I keep that voltage on the input of the comparator, when I re-turn on the dsPIC, the comparator does not react and its output is high.
...

Are you talking about on a real chip?
If yes, then you just violated the ABSOLUTE MAXIMUM RATINGS for the chip, which specifies that no I/O pin is allowed to go more than 0.3V above VDD.
 

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#7
FilippoMonti
Starting Member
  • Total Posts : 31
  • Reward points : 0
  • Joined: 2017/11/03 03:10:15
  • Location: 0
  • Status: offline
Re: Op Amp / Comparator Block: issue setting the voltage reference (DAC) 2019/07/01 00:47:08 (permalink)
0
Dear ric,
 
thank for you reply. Maybe I was not very clear.
 
Example:
I have the comparator threshold set to 0.275V on the positive comparator pin. Then, in the negative comparator pin I apply a voltage of 0.5V. --> The output of the comparator goes low as expected
Then, I turn off the dsPIC but I keep the 0.5V on the negative input of the comparator. I turn on again the dsPIC in this situation --> The output of the comparator is high.
 
Is it an explainable behavior?
 
Thanks
 
Filippo
#8
Lubin
Moderator
  • Total Posts : 360
  • Reward points : 5
  • Joined: 2007/03/31 07:38:15
  • Location: Bayonne, France
  • Status: offline
Re: Op Amp / Comparator Block: issue setting the voltage reference (DAC) 2019/07/02 02:04:06 (permalink)
0
Hi Filippo,
 
I think ric made an interesting point here regarding maximum 0.3V rating when the chip is not powered.
 
Regarding the comparator, its output is supposed to be the state. I did not see schematic mentioning edge triggered latch. You are beyond my knowledge with this peripehral.
Maybe you might couple the peripehral with an ADC to resolve this startup case ?
#9
ric
Super Member
  • Total Posts : 22715
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: offline
Re: Op Amp / Comparator Block: issue setting the voltage reference (DAC) 2019/07/02 17:09:46 (permalink)
0
FilippoMonti
...
Then, I turn off the dsPIC but I keep the 0.5V on the negative input of the comparator. I turn on again the dsPIC in this situation --> The output of the comparator is high.

0.5V > 0.3V
That will be partially powering up some internal logic, and possibly getting it into an illegal state.
Any problems that occur after exceeding ABSOLUTE MAXIMUM RATINGS are your fault.
 
 

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#10
FilippoMonti
Starting Member
  • Total Posts : 31
  • Reward points : 0
  • Joined: 2017/11/03 03:10:15
  • Location: 0
  • Status: offline
Re: Op Amp / Comparator Block: issue setting the voltage reference (DAC) 2019/07/04 00:28:38 (permalink)
0
Hi Lubin and ric,
 
I have retried by connecting the 0.5V to the same voltage power supply as for the 3.3V of the dsPIC. So that they shut down/turn on simultaneously. But, also in this situation the comparators does not work.
 
Coupling the comparators with the ADC as supposed by Lubin seems not working too (actually it works only on Comparator 3 but don't on the other two). But, using only ADC it works.
 
--> Does the comparators inside the dsPIC33EP256MC506 could be considered like "hardware" comparators or they are treated in some way by the software?
 
--> The comparators are way more speed than the ADC or not? I mean, is it really an advantage using the comparators for protection functions?
 
Thank you.
 
Filippo
#11
Jump to:
© 2019 APG vNext Commercial Version 4.5