Go Down

Topic: Reading MOSI data from Bosch ASIC, take 2 (Read 900 times) previous topic - next topic

blue2u

hi guys :

there was a previous post about using the Bosch CJ125 Asic

it was old  (jan) and long and i do not want to add at the bottom, so i start a new one

since i'm currently involved in an avr (poor avr) and a cj125, please allow me a few comments to the cj125 and the code found in the previous post "Reading MOSI data from Bosch ASIC"

the included code contains a 16-bit bit-banged SPI implementation specifically tailored for the cj125

i will include code or make more available upon request ... so don't jump on my "i would not"

i would not use floats on a humble 8-bit cpu
i would not use the built in spi functions
i would not use println

no com err check on rd or wr to the cj125

you can not run pid and expect the I-err-term being correct if you don't assure that the sampling and err-term calculations are done on a fixed period ... you assume that your main loop execution is always at the same loop cycle run-time basis
http://www.embedded.com/design/embedded/4211211/PID-without-a-PhD

yes ... this c++ code runs in the arduino ide

it is currently used to read the cj125 diag_reg with adr=0x78 and dat=0x00

it checks for the return of xx101xxx and if correct clocks the 2nd "dat" out and receives efiSpi.Dat and efiSpi.Adr

i would have more suggestions and some questions if anyone working with the cj125 is interested

i realize that it doesn't need to be in a class, but i like it this way

Code: [Select]

//---------------------------------------------------------------------------
#ifndef efiSpiH
#define efiSpiH
//---------------------------------------------------------------------------

class  TSpi ;
extern TSpi efiSpi ;

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

class  TSpi
{
public :

  enum { eRevSpi = 0x13030900 } ;

  static const DWORD cRevNum ;

//- - - - - - - - - - - - - - - - - - - - - - - - - - - -

private :

public :

  BYTE  Adr, Dat ;

  bool Com(BYTE adr, BYTE dat) ;

} ;

//---------------------------------------------------------------------------
#endif /* efiSpiH */



and here the .cpp ...

i like to have a simple revision indicator in every module like ...

const DWORD TSpi::cRevNum = { eRevSpi } ;

Type.h contains all the

typedef       unsigned short   int    WORD ;

Code: [Select]

#include <Arduino.h>

#include   "Type.h"
#include "efiSpi.h"

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

#define cCS   0x01
#define cMOSI 0x08
#define cMISO 0x10
#define cSCK  0x20

#define NOP __asm__ __volatile__ ("nop\n\t")

//---------------------------------------------------------------------------

TSpi efiSpi ;

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

const DWORD TSpi::cRevNum = { eRevSpi } ;

//---------------------------------------------------------------------------

bool TSpi::Com(BYTE adr, BYTE dat)
{
  bool ret = true ;     
       
/* noInterrupts() ; not working */
 
  PORTB &= ~cSCK ; /* 1st */
  NOP ; /* 2nd.0 */
  NOP ; /* 2nd.1 */
  NOP ; /* 2nd.2 */
  NOP ; /* 2nd.3 */
  NOP ; /* 2nd.4 */
  NOP ; /* 2nd.5 */
  NOP ; /* 2nd.6 */
  PORTB &= ~cCS ; /* 3rd */
  NOP ; /* space */

  for (BYTE i = 8 ; i-- ; ) { /* adr, MSB-First */

    PORTB |=  cSCK ;

    if (adr & 0x80) PORTB |=  cMOSI ;
    else     PORTB &= ~cMOSI ;

    adr <<= 1 ;

    PORTB &= ~cSCK ;

    NOP ;
    NOP ;

    if (PINB & cMISO) adr |=  1 ;
    else       adr &= ~1 ;

  }     Adr = adr ;

  if ((adr &= 0x38) == 0x28) { /* adr == xx101xxx */

    for (BYTE i = 8 ; i-- ; ) { /* dat, MSB-First */

      PORTB |=  cSCK ;

      if (dat & 0x80) PORTB |=  cMOSI ;
      else       PORTB &= ~cMOSI ;

      dat <<= 1 ;

      PORTB &= ~cSCK ;

      NOP ;
      NOP ;

      if (PINB & cMISO) dat |=  1 ;
      else dat &= ~1 ;

    }     Dat = dat ;
  } else {  Dat = 0 ;  ret = false ; }         
 
  NOP ; /* space */
  PORTB |=  cCS ; /* 1st */
  NOP ; /* 2nd.0 */
  NOP ; /* 2nd.1 */
  NOP ; /* 2nd.2 */
  NOP ; /* 2nd.3 */
  NOP ; /* 2nd.4 */
  NOP ; /* 2nd.5 */
  NOP ; /* 2nd.6 */
  PORTB |=  cSCK ; /* 3nd */

/* interrupts() ; not working */

  return ret ;
}
//---------------------------------------------------------------------------


while the cj125 is a sweet chip and now available, the correct application of the "pump current reference" in the "bosch diagram box 12"  for the lsu 4.9 sensor only is for me unknown at this time, as well as the settings in the wr_init2 register

cheers, blue2u

blue2u

meanwhile i figured it out ...

regarding the pump reference current and the lsu 4.9

bosch secretes are hard to crack ...

the lsu 4.9 datasheet talks about a nominal pump current of 20 uA (remember only lsu 4.9)

and a few pages down ... the ref-pump-current is during all measurements 20 uA continuous ...

the cj125 ic block diagram shows an internal programmable pump current device feeding into UN ??? ... why UN

the normal to be measured pump current pins are IP and IA and not UN ???

another bosch document suggests in a sample schematic, for the lsu 4.9 only, a 100k res from UN to Vcc (5V) ... now normally UN == UP at lambda 1 is at 2.95 V ... VM is 2.5V + internal 450 mV at US, which leaves 5 V - 2.95 V = 2.05 V over 100 k = 20 uA.

so an earlier doc implies with the 100k for the lsu 4.9 only a constant current of about 20 uA flowing into UN

the ic block diagram provides a programmable internal const current source (20 uA) into UN.

therefore these 20 uA have to flow into UN for an lsu 4.9 sensor to operate properly.

also a few (just a few) lsu 4.9 related web posts talk about an sensor internal ref-current, which is different from the lsu 4.2

i hope i'm not boring the arduino community.

so for all who use a cj125 on an arduino or otherwise these were my few cents of wisdom

thanks and cheers, blue2u

wiki.efiHacks.com

jtw11

Hi there,

Regarding the PM you sent me, and this regarding my old CJ125 thread - I will respond to this in the next couple of days as I am about to revisit it, but have been very busy with other things - but yes, you are right. The reference current is only for the LSU 4.9 sensor, the 4.2 does not use a reference current.

blue2u

hi Jtw11 :

thanks for your reply ... i wasn't checking on a regular basis and therefore the delay.

i would possibly have a few questions regarding the CJ125 and LSU4.x

i used my arduino as an ISP and it also powered the target board with atmega328p-au.
however i did not power the cj with 12V, but with 5 V only from the ISP during the initial download and other non cj related firmware tasks.

then i discovered that a bosch spec says that

Vub < Vcc ... during power up 100 ms max ... accumulated over lifetime 2 h max.

i did so violate the specs for Vub not being less than Vcc.

i did a correct setup of the cj i believe and observed the following on pin UN.

cold sensor about 3.5 kHz square wave with rc flanks, which is correct. this is the wave form from pin CM forcing the Ri measurement current through the cold nernst cell.

but when i slowly cranked up the heater ... slowly with a variable power supply i saw the amplitude slowly getting smaller as the Ri nernst got smaller and then it got very distorted right near the t7 nernst cell open short measurement timing ... hard to describe ...

also as i was performing a test with a regular pot instead of the nernst cell, the 3.5 kHz amplitude got smaller as i lowered the Ri simulation, with no distortion.

the distortion came from the pump cell therefore.

i tested the sensor on a known good cj125 design where i purchased the board and it worked fine, so the sensor seems ok.

i assume that the cj125 is somehow damaged ... it's hard to follow all the details of the cj125 and it's internal timings, even being somehow explained.

i abandoned the atmega and redesigned the board with an arm lpc1347 ... ported the firmware and have a smooth sailing so far ... only on the arm eval board so far ... expect the 1st 2 boards from pcbexpress, now sunstone circuits, next week.

got a soic-24 cj125 now instead of the lqfp-32 which is a nightmare to probe the pins or to replace to begin with.

what were your experiences so far ... i would be very very interested to hear :)

thanks for your reply so far and cheers, blue2u

p.s. if you want to handle this topic for whatever reason "off this forum" to not get the arduino community bored, it's fine with me too ... i would prefer the forum ... maybe others are interested as well.

anyway you can also email me at efiHacks@gmail.com or efiLabs@gmail.com





huayu_66

hello,
   I'm cj125 measurement, but has a problem, it does't work, please help me.
   I measure UR 4.9 v output unchanged, and does not change with temperature, I want to know is I have a problem is a problem with the peripheral circuit or chip, circuit according to the chip manuals, I measured the RST side, 4.4 v is not reset state, VM US output is 2.48 v to 2.48 v output, RM reverberate for square wave, the frequency is about 3.1 KHZ, I measured the OSZ side, the output around 1.7 v, the oscilloscope can only see burr, not sine wave or square wave, want to ask whether the chip no vibration, in a reset state?
  Circuit is not heating MOS tube, directly by the power heating, by single chip microcomputer cannot achieve SPI communication. Whether the chip broken?
  I'm sorry my English is very bad.
  Who can help me , my e-mail is 243710566@qq.com or wangmeitong@126.com ,please help me ,I'm very very thank you.

Go Up