Can I do this with one cog? (solenoid control with current feedback)
Intrepid
Posts: 6
I need to drive a solenoid via PWM ( using a peak and hold methodology) controlling the duty cycle based on a single channel ADC monitoring a current sense resistor. The ADC communicates via SPI. Can this be done with 1 cog?
Thanks,
John
Thanks,
John
Comments
-Phil
The PWM frequency is dependent on the inductance of the solenoid for now let's assume 1 KHz - 10 KHz. I am not very familiar with the propeller architecture at this point, what is the reasoning behind the external XOR? I am hoping to control 6 solenoids in this manner and interface the propeller to a DSP so it may be difficult to spare 2 pins for each channel as that would be 5 pins per channel (3 for SPI and 2 for PWM) not leaving enough for the DSP to talk SPI to the prop. I am trying to decide between the propeller and a small FPGA.
Thanks,
John
This is for fuel injection, right? You could have one cog doing the PWMing for all six solenoids. Another could handle the ADC(s) and compute the necessary PWM outputs. What is the DSP doing? Are you sure that can't be handled by the Prop, as well?
-Phil
I think I am missing something. Why would you need to use 2 counters and an XOR? Would't one counter per solenoid work just fine?
Doug
The DUTY mode output from a counter is too fast to switch a solenoid driver efficiently. To do that you need PWM instead. But PWMing can't be done autonomously with a single counter. It needs a software assist from the Prop, which is pretty much a full-time occupation. (An 8-bit PWM at 10KHz requires a timing granularity of less than 8 assembly instructions.) The OP stated that he wanted the PWM and SPI in one cog. While not impossible, the code would be a bit opaque, since servicing PWM and SPI would have to be interleaved. But by using two counters and XORing their outputs, you can get a PWM output whose duty cycle can be varied from 0 to 100% just by varying the counters' relative phase. This continues without further program assistance (until a different duty cycle is called for), thus freeing the cog for reading the ADC in a simple and timely fashion.
But when the OP said he had six solenoids, that changed the whole scenario, since one cog can just as easily drive six solenoids using software as it can one using an object from the OBEX.
-Phil
Are you saying that in duty mode the frequency is too high so at a FRQ of 2147483648 would give you a 50% duty cycle, but the output frequency is still 80MHz?
What kind of frequency do you need for a solenoid? I would guess you would want something above 20KHz to keep it out of audible range.
So the solution you are suggesting is using 1 main cog for spin, 6 cogs for SPI, and one COG for 6 interleaved PWMs?
Thanks,
Doug
At 50%, the duty mode output would be 40MHz; at 25%, 20MHz. This is way too fast to drive a solenoid driver. It would spend most of the time in its linear region and overheat. The optimum PWM frequency is dependent on the solenoid's inductance and switching characteristifcs of the driver circuitry. Audibility is a secondary concern — especially if the solenoids are out of earshot or in an already noisy environment.
You probably would not need six cogs for the SPI. In fact, if they shared common clock, /CS, and Din lines, one cog could probably handle it.
-Phil