Quantcast
Channel: Infineon Forums
Viewing all 9892 articles
Browse latest View live

Adding ADC to Microcontrollers without ADC

$
0
0
I recently had the need to carefully measure a voltage with a microcontroller which lacks an analog-to-digital converter (ADC),
and I hacked together a quick and dirty method to do just this using a comparator, two transistors, and a few passives.
The purpose of this project is to make a crystal oven controller at absolute minimal cost with minimal complexity.
Absolute voltage accuracy is not of high concern (i.e., holding temperature to 50.00 C) but precision is the primary goal (i.e., hold it within 0.01 C of an arbitrary target I set somewhere around 50 C).
Voltage measurement is usually a balance of a few factors: precision, accuracy, cost, simplicity, and speed. The method I demonstrate here maximizes precision and simplicity while minimizing cost.
High speed operation is not of interest (1-2 measurements per second is fine), and as mentioned before accuracy is not a chief concern as long as precision is maximized.
I would feel neglectful if I didn’t give a shout out to a few alternatives to this method: Using the 10-bit ADC built into most AVR microcontrollers (my go-to for ATMega328 at ATTiny85,
but the ATTiny2313 doesn’t have any) often combined with an op-amp like this, using an IC like the MCP3208 8-channel 12-bit ADC (very expensive at $3.66 on mouser) are a good option,
and fancy alternative dual slope methods as described in this really good youtube video and even mentioned nicely in the digital volt meter (DVM) / LCD driver ICL1706 datasheet.
Those addressed, my quick and dirty idea uses only a couple cents of components and 3 pins of a microcontroller. There is much room for improvement (see my notes about a 555 timer,
voltage reference, and operational amplifiers at the bottom) but this is a good minimal case starting point.
This type of measurement is perfect for high precision temperature measuring using things like an LM335, LM35, or thermistor.
The concept behind this method is simple: use a current-limiting circuit to charge a capacitor at a constant rate so voltage
rises linearly with time (rather than forming an exponential RC curve), and time how long that voltage takes to cross your test voltage.
A circuit which compares two voltages and outputs high when one voltage surpasses the other is called acomparator,
and many microcontrollers (including ATMEL AVRs) have analog comparators built in (which compare AIN0 and AIN1,
the result of which accessable by accessing the ACSR&(1<<ACO)) bit value (at least for the ATMega328, according to the datasheet).
I can use the AVR’s comparator to time how long it takes a capacitor to charge to the test voltage, and output to that to the serial port.
Note that I designed this entire circuit to use the most common transistor/resistors I could think of.
It can be fine-tuned to increase speed or increase precision, but this is a great starting point.
To generate a constant current I need a PNP transistor (I had a 2N2907 on hand) with a voltage divider on the base and a current limiting resistor above the transistor for good measure (in retrospect,
with a more carefully chosen set of values this may not be needed). This is all that’s needed to charge the capacitor linearly and generate a positive ramp.

My test setup is a mess, but it demonstrates this idea works well, and is stable enough to run some experiments.
In the frame you can see the ATMega328 microcontroller (big microchip), LM335 temperature sensor (the TO-92 closest to the MCU), a TTL FTDI serial/USB adapter (red board, top), and my USBTiny AVR programmer (blue board, right), and oscilloscope probes.

To prevent this linear charger from charging forever, I make the microcontroller read the comparator which compares my test voltage with that of the ramp.
If the test voltage is reached, or if the ramp reaches a cutoff voltage first (meaning the test voltage is too high to be measured),
the count (time between last reset and now) is sent to the computer via serial port, and the capacitor is discharged through a PNP resistor. In the schematic,
this is the “reset” pin. Note that the “measure” pin is AVR AC0, and AC1 is the test voltage.
When all this is assembled, you can see how the linear ramps are created every time the reset transistor shuts off.
Note that every 10th ramp is higher than the rest (shown here as the one left from center). This is because every
10th reading the data is summed and sent to the serial port, causing a little extra time before it is reset again.
While the time value has been recorded of the comparator match of the test voltage and the ramp voltage,
the capacitor is allowed to continue charging until the next cycle.
Interestingly, this method is largely insensitive to power supply noise.
I’m using an extremely Attachment 2717
Attachment 2718
Attachment 2719
Attachment 2720
Attachment 2721noisy environment (breadboard, DIP power regulator) but the recordings are rock solid.
I suspect this is because the ramps are timed based on constant current, not abbsolute voltage, and that the ramps are
fast enough to not be sensitive to slow changes in voltage. In reality, I don’t think I can adequately explain why the readings
are so good when the supply is so shaky (the positive voltage rail is all over the place). It works, so I’m happy with it, and I’ll keep pushing forward.

Lately I’ve been using RealTerm as a feature-rich alternative to HyperTerminal and a more convenient method
than requiring custom python scripts be written every time I want to interact with the serial port in a way that involves
debugging or logging or other advanced features. Here you can see the real time output of this device logging time to
comparator match as it also logs to disk in a text file. This is great for simultaneously logging data (from RealTerm)
and graphing it (from custom python scripts).

This is what happens when I touch the temperature sensor for about 30s. I’m recording the time to voltage crossing of an
LM335, so the number decreases as temperature increases. Also each data point is the average (actually the sum) of 10 points.
It would be trivial to create some voltage test points, create a calibration curve, and infer the voltages involved,
but this is more than enough already to prove that this method is robust and clean and precise and

If I let it run for about an hour, I catch my air conditioning coming on and off. Warmer temperature is higher voltage which means less time to charge,
so the downslopes are my AC cooling my home and the up slope is my home passively warming.
The fluctuations are only about 100 units which I (backwards calculate) assume are about 1-2 F.
These numbers seem so arbitrary! How can we calibrate this? This opens up a Pandora’s box of possible improvements. I’ll close by saying that this project works great exactly how it is to meet my needs. However, some modifications could be made to change the behavior of this device:
• Slowing things down: A larger capacitor value (or higher resistor value) would increase the time or charging, lengthen the time to comparator threshold crossing, and increase precision. The readings would be slower (and more susceptible to noise), but it’s an option.
• Self-calibration: Components (Rs and Cs) are sensitive to temperature and charge time can fluctuate with age, wear, temperature, etc. To self-calibrate with each sweep, add an additional comparator step which compares voltages between a precision voltage reference and your ramp would be a way to self-calibrate your ramp charge rate with each sweep. Optimally do this with two voltage references (3.3V and 1.8V are common) but comparing 0V to a single voltage reference would be a great step.
• Don’t have the microcontroller gate: A 555 is perfectably capable of generating pulses to reset the ramp every so often, and frees up a pin of the microcontroller.
• Use an op-amp for constant current charging. It seems like a lateral move, but if your deign already has an op-amp chances are there may be some unused amps, so eliminate a transistor for this purpose! Check out the constant current source section from TIs handbook on operational amplifier applications.
• Use an op-amp for the comparator(s). The microcontroller’s comparator is handy, but if yours doesn’t have one (or you don’t feel like using one) configuring an unused op-amp stage as a comparator is a good option. The digital output could also trigger an interrupt on the digital input of a MCU pin as well!
• Use timer and counters to measure time while using an external interrupt to gate the count. Your microcontroller’s on-board counter is likely extremely powerful so utilize it! This example doesn’t use it actually, but using it would let you count up to the CPU clock’s frequency of ticks between ramp starts and the comparator match.
• Eliminate the microcontroller. Yeah, you heard me. If you use an op-amp keep resetting the ramps, and op-amp comparators to generate digital outputs of threshold crossings, you can use a standard counter (configured to latch then clear when the reset event is engaged by the 555 which induces resetting of the ramp by draining the capacitor), just use a counter IC to capture the value. You can clock it as fast as you want! You could even have it output its value directly to LED or LCD displays. In fact, this is how some digital volt meters work without the need for a microcontroller.
?????

Questions regarding Infineon BTN8962

$
0
0
I want to design a BDC driving board with Infineon BTN8962.(Infineon BTN8962 is a half of H-bridge IC)

As we all know,BDC driving circuit is just like this:

In this picture,We set a High side MOS(QA) as Open,and set a High side(QC) and a Low side(QB) MOSes as close.We just have to ouput a PWM signal to control the speed of BDC.


But when I use Infineon BTN8962,I found I cound not do this unless using the INH pin as PWM signal input pin.(But in fact,this pin is sleep mode enable pin.It can close its MOS.)

Which pin should I set as PWM signal output pin?

GUI_SEGGERLIBRARY problem

Advice set up a continuous repeating PWM signal different freq/duty over 2 time slots

$
0
0
Hi Deni,

I have a quick question regarding this.. my period and compare are firing off too soon. I followed the formula you used in the link you pointed me to, VERY HELPFUL thank you!...

But the documentation is not exactly clear on which slice should hold the "Event" that should be done once the period or compare is fixed.

Here is what I am doing....

Currently I'm using CCU42_CCU42, CCU42_CCU43.
I have the timer_concatination bit turned on in CC42_CCU43.

I'm currently calling XMC_CCU4_SLICE_CompareInit(...) for both CCU42_CCU42 and CCU42_CCU43.
Enable Shadow Registers, both slices.

EnableEvent form compare and period in BOTH CCU42_CCU42 and CCU42_CCU43. I've tried one or the other and it's doing strange things.
So I'm sure this is where my problem is.

I also hook up the period and compare match events to SR0 and SR1 for both.

Anything you add to this would be most helpful. As you can see I'm a bit lost. :)

Thanks for your help.

ATMEGA324A - ECG Atmel Assembler programming using RS232.

$
0
0
Good evening, im 3rd year physics engineering course and we're doing an ECG in PCB and using ATMEGA324A as the microcontroller along with the biomedical engineering course.
Me and my group mates are having a really hard time with coding this, since we have absolutely no microcontroller programming background, let alone assembly programming bases, and this project has been an overall struggle.
So i'm here asking you guys for help, any books, online courses, pdf's or whatever help you could recommend would be greatly appreciated. Thank you.

XMC4500 Tip of the day: Cortex-M4 Processor Mode and Privilege Levels

$
0
0
In my application running with RTX I would like to change to unprivileged mode after the initialization (interrupt vectors, etc.) has been done.
Is this a good idea?
How can I change the mode from C code? Is there a XMC-library API for this?

DALI and XMC

$
0
0
Hi
3 questions;

1. when I buy a XMC chip, will i get the DALI protocol stack as library for free? Will I also get the source code?
2. which version of DALI is implemented?
3. has the IFX software/firmware gone through any standardized tests like the DALI compliance test mentioned on
http://www.dali-ag.org/trademark-tes...i-testing.html

Thx
M.

Permanent damage to XMC1300 caused by E_EEPROM_XMC1 Dave 4 APP

$
0
0
Hi,

DAVE4 E_EEPROM_XMC1 APP is using the ROM function to erase the flash as recommened by the errata.

Regards,
Jesus

XMC4200 PSRAM Mapping

$
0
0
Hi,

Find attached the linker file for XMC4200x256.
By default the linker file is copied into your project at project creation based on device selection.
How did you get the memory sections your were describing below?

Regards,
Jesus
?????

Dave IDE cannot update to v4.3.2 automatically

Video: ClarinoxBlue SPP on Infineon XMC4700

Interfacing with security module

$
0
0
Hi Sridhar,

We kindly ask for your understanding that we cannot discuss this case regarding a problem with SPI commmunication with a SLI97 security chip herein the forum. Please send this case via www.infineon.com/tac form.

Thank you.

XMCLIB: best practice example for CAN reception? (XMC4500)

$
0
0
I try to receive CAN messages with 2 different CAN-Ids on a XMC4500. I have configured 2 message objects, allocated them to the Node list, configured and enabled 2 IRQHandlers and am able to receive messages with both IDs correctly.

Important parts of the configuration:
Code:

XMC_CAN_MO_t RxMsgObj =
{
  .can_mo_type      = XMC_CAN_MO_TYPE_RECMSGOBJ,
  .can_id_mode      = XMC_CAN_FRAME_TYPE_STANDARD_11BITS,
  .can_priority    = XMC_CAN_ARBITRATION_MODE_ORDER_BASED_PRIO_1,
  .can_identifier  = (uint32_t)0x750,
  .can_id_mask      = (uint32_t)0x7AF,
  .can_ide_mask    = 1U,
  .can_mo_ptr      = (CAN_MO_TypeDef*)CAN_MO1,
  .can_data_length  = (uint8_t)8,
  .can_data[1]      = 0,  // auch über can_data_byte[0..7] zugreifbar!
  .can_data[0]      = 0
};
[...]
  XMC_CAN_AllocateMOtoNodeList((CAN_GLOBAL_TypeDef*)CAN, CAN_CFG_NODE_NUM, 1);  // MO 1
  XMC_CAN_AllocateMOtoNodeList((CAN_GLOBAL_TypeDef*)CAN, CAN_CFG_NODE_NUM, 2);  // MO 2
  XMC_CAN_MO_Config(&RxMsgObj);
  XMC_CAN_MO_Config(&RxMsgObj2);
  XMC_CAN_MO_SetEventNodePointer(&RxMsgObj,  XMC_CAN_MO_POINTER_EVENT_RECEIVE, 7);
  XMC_CAN_MO_SetEventNodePointer(&RxMsgObj2, XMC_CAN_MO_POINTER_EVENT_RECEIVE, 6);
  NVIC_SetPriority(CAN0_7_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(), 63U, 0U));
  NVIC_SetPriority(CAN0_6_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(), 62U, 0U));
  NVIC_EnableIRQ(CAN0_7_IRQn);
  NVIC_EnableIRQ(CAN0_6_IRQn);
  XMC_CAN_NODE_DisableConfigurationChange(CAN_CFG_NODE);
  XMC_CAN_NODE_ResetInitBit(CAN_CFG_NODE);

Here's the interrupt handler:

Code:

void CAN0_7_IRQHandler(void)    // Handler for message A (the handler for message B is similar, but with RxMsgObj2)
{
  uint32 ulMOStatus;

  /* CAN-Buffer 1 ------------------------------------*/
  ulMOStatus = XMC_CAN_MO_GetStatus(&RxMsgObj);
  if(ulMOStatus & XMC_CAN_MO_STATUS_NEW_DATA)
  {
        gMsgQueue.ucWriteIdx++;
        if(gMsgQueue.ucWriteIdx > CAN_MSG_QUEUE_SIZE - 1)
            gMsgQueue.ucWriteIdx = 0;

        XMC_CAN_MO_Receive(&RxMsgObj);
        gMsgQueue.asMsg[gMsgQueue.ucWriteIdx].ulId = RxMsgObj.can_identifier;
        memcpy(&gMsgQueue.asMsg[gMsgQueue.ucWriteIdx].aucData[0], &RxMsgObj.can_data_byte[0], 8);

        XMC_CAN_MO_ResetStatus(&RxMsgObj, XMC_CAN_MO_RESET_STATUS_NEW_DATA); // TODO: Leads to an exception sometimes
  }
}

But, the following sequence leads to an exception:
- receiving message A and sending response
- receiving message B: call to XMC_CAN_MO_ResetStatus() leads to an exception, because RxMsgObj is empty (0). The interrupt handler is called over and over again, with no ne data available.

Question:
What is the correct method to get the data of a received message, copy it to my own Message Queue and acknowledge/reset the message object/interrupt?
Could anyone post a "best practice example"?
(I studied the XMCLIB docu, but it's not very helpful, only describes the individual functions, but not whích one to use in which order. Also, a search of forums and Google didn't help. PS: I have to find a solution without APPs due to performance reasons)

Any hints welcome! Thanks a lot!
Jyrki

GUI_SEGGERLIBRARY problem

$
0
0
Hello

So glad someone replied.
My project zip file is 15mb and the attachment limit is 10mb.
How to go about it?

Meanwhile you can find the response sent to someone from IFX
earlier, in docx form.
?????

Changing walktime in XMC1202 on the Arduino shield to low values

$
0
0
Hi Martin,

I´m still not on a vacation (finally from Friday :p) but I changed my work position so I don´t have much time as before to devoted to our beloved forum. I sometimes reply on some questions that I can clarify in some minutes. Unfortunately, you need pretty long reply while you asked me so many things :D.
Still, I will send you an answer as a Christmas present :cool:

And, please feel free to use my suggestion; microcontrollers are not so sensitive things that one wrong look will damage them. After all,
Code:

"Only while using the code and playing with it, you will learn something."

                                          Unknown wise software developer

At the end, I will write you some ideas, explanations and/or suggestions, not whole, production-ready function. I don´t want to be guilty if your lab assignment or master thesis is not working ;)

Best regards and expect Santa Claus soon,
Deni

ADC triggered by PWM is not getting the ADC Complete interrupt.

$
0
0
Did not work. I actually, for fun, enabled these IRQ's.. None of them hit.

/* Config the NVIC */
/* Set Priority */
NVIC_SetPriority(VADC0_G0_3_IRQn,IRQ_PRIORITY);
/* Enable */
NVIC_EnableIRQ(VADC0_G0_3_IRQn);

/* Set Priority */
NVIC_SetPriority(VADC0_G0_2_IRQn,IRQ_PRIORITY);
/* Enable */
NVIC_EnableIRQ(VADC0_G0_2_IRQn);

/* Set Priority */
NVIC_SetPriority(VADC0_G0_1_IRQn,IRQ_PRIORITY);
/* Enable */
NVIC_EnableIRQ(VADC0_G0_1_IRQn);

/* Set Priority */
NVIC_SetPriority(VADC0_G0_0_IRQn,IRQ_PRIORITY);
/* Enable */
NVIC_EnableIRQ(VADC0_G0_0_IRQn);

Tutorials for using Debug functionality

Using an AC Rated Contactor for DC Circuits

$
0
0
I have a few questions:

1) Could we use an AC rated Contactor for DC switching? I have heard that typically the switching voltage a AC contactor can handle at DC for the same current is 10 times less. How do we arrive at this scaling factor of 10 times? Is it a practical figure or a properly calculated number?
Both of them are DC to DC converters. Both switching regulators and switching controllers can be obtained/configured in either buck (output voltage < input voltage), boost (output voltage > input voltage), or both topologies.
Does it mean that a contactor rated to switch 690V AC, 20A can handle 69V DC, 20A?

2) What is the fundamental limitation on switching DC vs AC. Is it just the longer sustained arc? If so, in case I use proper snubbers/ arc suppression circuits could I make use of AC rated contactors for DC?
A switching regulator works by taking small chunks of energy, bit by bit, from the input voltage source, and moving them to the output. This is accomplished with the help of an electrical switch and a controller which regulates the rate at which energy is transferred to the output (hence the term “switching regulator”).

The energy losses involved in moving chunks of energy around in this way are relatively small, and the result is that a switching regulator can typically have 85% efficiency. Since their efficiency is less dependent on input voltage, they can power useful loads from higher voltage sources.

Switch-mode regulators are used in devices like portable phones, video game platforms, robots, digital cameras, and your computer.

Switching regulators are complex circuits to design, and as a result they aren’t very popular with hobbyists. However Dimension Engineering creates switching regulators that are even easier to use than linear regulators, because they use the same 3 pin form factor, but don’t require any external capacitors.
3) Most relays and contactors are rated for resistive and moderately inductive loads. In case I am switching capacitive loads the switching becomes very bad and leads to welding of contacts. What is the best recommended approach to overcome this?

4) What is the fundamental difference between force guided relay and a contactor. Let's say both are at the same current rating.

Cheers!

About XMC4300 cached and uncached flash memory

$
0
0
I am new to XMC.
During debugging, which part of the memory will the program be used/located, cached or uncached?

Thank you
Regards,
Herry

EEPROM which connected to EtherCAT slave(XMC4300)

$
0
0
Hi,

How can i program the EEPROM which connected to EtherCAT slave(XMC4300) from a master side(TwinCAT)?
Any example/guideline?:o

Thank you
Regards,
Herry
Viewing all 9892 articles
Browse latest View live


Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>