Of course, we’re not exactly bursting at the seams…
What do we need to do in preparation?
Now that I am holding my PSOC4 kit, it says to install from
http://www.cypress.com/CY8CKIT-042
It needs a registration though, which I am OK with so far.
So, anyone else wants the kit from element14?
Thinking about a project with this kit.
Having started with the esp8266, I am interested in the power issues I encountered. a 1Msps DSO will be good for looking at any fluctuations, and the PSOC4 can do this. So designing a basic DSO will be of actual use to me. Adding more RAM will probably be necessary if the data cannot be pushed out (over USB?) fast enough.
BTW, I see that the PSOC 4 M-series (CY8CKIT-044) is now available for pre-order from cypress for the same price. It has a few additions, and I would like to have an RTC and some FRAM. Maybe next time, I will use i2c/spi devices for now.
Please get yourself the latest version of PSOC Creator 3.1 setup. If anyone is struggling for bandwidth (I can’t remember how big the download is), I can bring the installer along.
Feel free to have a play around and look at some of the tutorials online if you like. We can just pick up from wherever everyone has got to. The tutorials online are ok…ish. I think they miss some of the fundamental detail of configuration that you really have to dig to find out. I feel they’ve somewhat done their tutorials to address a “my first microcontroller” crowd, which is fine, but there’s some real gems hidden below that.
I’m liking the look of the PSOC M devices, they’ve addressed the middle ground between the PSOC 4 (small & cheap) and the quite large PSOC 5 (quite expensive.) Adding a DMA and more RAM adds quite a bit of capability.
As a side note, the PSOC 4 pioneer kit has a PSOC 5LP on the board being used as a programmer. Whilst I haven’t done it, I have read many times people are programming the on-board PSOC 5 using the boot-loader as it has it’s pins broken out as well. In fact, at least for a while there, the PSOC 4 pioneer kit was the cheapest way to get your hands on a PSOC 5LP breakout board.
The big difference for the project you’ve described is built in USB and DMA.
FYI, the recent eevblog
http://www.eevblog.com/2015/03/11/eevblog-722-mailbag/
talks about the new CY8CKIT-042-BLE PSoC 4. Around 38-45 minutes.
Not giving much tech info but showing off the app.
Part 1:
-
Create a new project (PSoC 4200 Design template)
-
Add a digital output pin
-
Open the pin configuration, name the pin, turn off hardware connection. (Optional) Turn on external connection
-
(Optional) Draw the external circuitry, using parts in the “Off-Chip” tab of the component catalogue.
-
Open the cydwr file and place the pin.
-
Build the API using menu Build > Generate Application
-
Open main.c
-
Add the following #defines:
#define SYSTICK_INTERRUPT_VECTOR_NUMBER 15u
#define BUS_FREQ 24000000u
#define SYSTICK_FREQ 1000u -
Add the SysTick ISR function
volatile uint32 ticks = 0;
CY_ISR(SysTick_ISR)
{
if(ticks++ % 500 == 0)
LED_Write(~LED_Read());
} -
Add the SysTick setup code
/* point the Systick vector to the ISR /
CyIntSetSysVector(SYSTICK_INTERRUPT_VECTOR_NUMBER, SysTick_ISR);
/ Set the number of ticks between interrupts.
Ignore the function success/fail return value */
(void)SysTick_Config(BUS_FREQ / SYSTICK_FREQ);CyGlobalIntEnable;
-
Program the device using the “Program” toolbar button or Ctrl+f5. Or you can start the debugger using the debug button or f5
Part 2:
-
Create a new project (PSoC 4200 Design template)
-
Open the TopDesign file
-
Add a digital output pin
-
Add a Digital\Functions\Timer Counter (TCPWM)
-
Add a System\Clock and wire it to the clock input of the timer, default value is 12MHz. Open the configuration and change it to 1MHz.
-
Add a System\Interrupt, wire it to the overflow pin of the Timer, name it.
-
Open the Timer configuration and Timer/Counter tab
Note: we need to count up to 500k to get half a second with a 1M clock, with a 16b timer that’ll need a prescaler of 8 and a max count of 62,500.
- Set the prescaler to 8.
- Set the period to 62,500.
Note: the interrupt is set to “On terminal count”, so the interrupt pin with toggle at that time.
-
Add a digital output pin, name it, turn off HW connection.
-
Open the cydwr file, place the pin, generate the API
-
Open main.c
-
Put the setup code into the main function
Timer_INT_StartEx(TimerLED_ISR); // Put the interrupt routing into the vector table
Timer_1_Start(); // Starts the timer
CyGlobalIntEnable; // Enables global interrupts -
Add the ISR function
CY_ISR(TimerLED_ISR)
{
LED_Write(~LED_Read());
}
Part 3:
-
Starting with the previous project, remove the interrupt component and comment out all the interrupt code we added.
-
Make sure the timer start is still included in the main function.
-
Open the output pin configuration and add the HW connection back in.
-
Add a Digital\Logic\Toggle Flip Flop, wire the clk input to the OV output of the timer, wire the Q output to the LED pin.
-
Add a Digital\Logic\Logic High ‘1’, wire it to the T input of the flip flop.
-
Rebuild and program the device.
Hi all,
got the PSoC to drive a 16x2 LCD display today. Very straight forward. Used P2[0-6] which unfortunately uses up all the analog pins on the shield connector.
Cheers,
Steve
Stephen,
If you want to save some pins (and you have some spare change) then consider something like this I2C expander
http://www.aliexpress.com/item/-/1967892309.html
Or even a more generic i2c expander. Or, in the spirit of DIY, get just the IC and build your own circuit…
cheers
Eyal
Forgot to say that I have that i2c->LCD board which you can try if interested. Got it recently and did not yet figure out the pinout (not shown on the board) but this should be easy to do.
Eyal
Thanks Eyal,
I already have an I2C LCD backpack board here somewhere.
Besides, I don’t believe the generated code will work over I2C. Works fine with a 7 pin port, even downloads a custom character set just fine.
Steve
Maybe I am a bit slow now (it is before midnight) but I do not understand what may not work over i2c. Can you elaborate?
Back to the PSoC. I am toying with acquiring a DSO, which will probably be in the 3-4k range to be good long term (200MHz, deep memory, 4 channels…). Then I thought I could get a cheap ($500?) 100MHz/2ch Rigol. I then thought that for my first need, tracking the power usage of the esp8266, I could DIY… So I picked up the PSoC4 and educated myself in the use of the ADC (and the USB bridge). Turned out to be simple but it did take me a little while to find my way.
I placed a 1ohm resistor on the 3.3v line and am measuring the voltage across it (diff ADC). It is interesting to see.
The PSoC reads the ADC, delays 1ms and loops. But a loop is longer than 1ms (adjusted in the plot).
The esp8266 reads a sensor, sends to a server (over wireless) then dsleeps for 5 seconds. This is just a test.
When sleeping the power usage is lost in the noise, but when active it is interesting to see the sharp peaks, probably when wireless activity happens, like the initial association. Around 230mA (at 1ohm 1mv is 1mA) means one needs a good power source. It has a larger spike on initial power up. The AMS3117 should pull 800mA but some other nice ultra-low-Iq LDOs can only do 150mA or such. Here is a detail of an active phase:
Some peaks are very short but the initial one has some body.
I need to figure this out. The reality is that the esp8266 (as the small flash) is specced for 1.8-3.6v (I think) so should not worry. The sensor is not that obliging. I need to have a good, reliable battery based power setup, and I cannot afford a few mA leakage.
Anyway, are we going to do a next class? That power meter app maybe? If it has a good timer then it should be possible to accumulate this info. I will follow up by myself but should be fun to make an evening of it one day.
I can safely say that for me the PSoC paid for itself already.
cheers
Nice job with the current measurement.
Sorry I’ve had a couple of interstate trips that have consumed a lot of time since the last workshop.
So yeah, lets do it.
I’ve attached two pics, the first one is the typical input circuitry (albeit without analog filtering) for a DMM voltage measurement. Second one I’ve removed all the switches to make it just a single range. That’s essentially what we’re trying to implement on the PSOC for the power meter as well as measuring the voltage drop across a resistor like you’ve already done for current measurement.
DMM front end
Simplified front end for single range
So have a go at working how we’ll do that in the PSOC, then we could meet up and work through any problems that crop up. How does that sound? Say meet up next week?
PS
Typically DMMs have a 10Mohm input resistance (R1 in the diagrams above.) That won’t work on the PSOC because it has too high a leakage current on the opamp inputs. Instead if we use 1M we should be ok.
Input voltage range will be 0.5 * Vdd * R1/R2
I connected the lines directly, differential mode, no conditioning:
OK, so I cannot draw. Something for the third class?
cheers
I have improved things somewhat.
-
The ADC mow samples at 1Msps, and I read (and accumulate) it at 100Ksps. I log at 1Ksps. This is interrupt driven so the time axis is accurate. I am not convinced that the PSoC can handle 10K sampling rate, even though a log entry is only about 10 chars, so 10KB/s->100Kbps which is too close to the 115Kbaud I use. I could try to push the UART higher but I doubt it will work (I had some issued with the current rate already).
-
I finally realized that I need to connect the gnd of the esp to GND of the PSoC (they are powered differently) and I now have much cleaner plots.
If I manage to get the esp to run reliably for a few hours then I will collect the desired power usage. But I also need to add an input scaler if I want to measure the uA deep sleep current - it shows as essentially zero in the graphs.
Maybe I need to set up two ADC channels, one as now (1.024v ref) and one with a 1.024mv and select the proper one at read time. I did not see an internal voltage reference that I can scale, maybe I can use the DAC?
cheers
You wont be able to use the DAC, because it’s an IDAC designed for Cap Sense circuits. Very different beast to a traditional voltage output DAC.
Also unlikely you could use a much lower ref voltage and still get good noise performance. I’d suggest using one of the opamps to amplify the signal, then use one of the muxes to switch between resistors at run time to change the current range.
If your PSOC and ESP are powered separately, you’re much better off from an analog perspective pinning the ESP ground to Vdd/2, and differentially measuring. That keeps it away from the PSOC supply rails, where all the analog circuitry will develop some artifacts. We can talk more about this at the space if you want, when are you next going in?
I’m surprised you couldn’t go much above 115200. I’ve very successfully used a uart up to several MBits on ARMs before for transmit, however it does depend on the PC side of it. Having said that, the PSOC 4 doesn’t have DMA or a deap FIFO which makes fast comms very difficult. How deap is the PSOC 4 UART FIFO? Does it hold a complete sample? Or are you having to wait?