Author Topic: AIS226DS / MOD-SMB380 I2C evaluation on LPC2378-STK  (Read 69986 times)

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3056
    • View Profile
    • uTasker
Re: AIS226DS / MOD-SMB380 I2C evaluation on LPC2378-STK
« Reply #30 on: May 27, 2010, 11:53:53 AM »
Hi

To display processor registers in the simulator follow the example at the bottom of page 5 of the following document:

http://www.utasker.com/docs/Coldfire/uTaskerM5282.PDF

Regards

Mark


Offline kb1gtt

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
Re: AIS226DS / MOD-SMB380 I2C evaluation on LPC2378-STK
« Reply #31 on: May 27, 2010, 10:51:29 PM »
Now if utasker wasn't already cool enough, you had to go and put tricks like that in it. Simply drag and drop to the simulator when the simulator is paused, and you can see about any thing you want. Nice. I can't wait to try it out.

Offline kb1gtt

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
Re: AIS226DS / MOD-SMB380 I2C evaluation on LPC2378-STK
« Reply #32 on: May 28, 2010, 11:40:01 AM »
I believe I'm having some trouble pausing the simulator. Right now when I select, then drag the text ucLPC23xx.ucSCM from LPC23XX.h, I get a circle with a line through it, indicating that this type of drag and drop isn't allowed by windows. I tried inserting a break point in the code then dragging and dropping, I also tried hitting the pause (Break All) button, but no dice.  I didn't see a pause command in the simulator pull downs.

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3056
    • View Profile
    • uTasker
Re: AIS226DS / MOD-SMB380 I2C evaluation on LPC2378-STK
« Reply #33 on: May 28, 2010, 12:03:42 PM »
Hi

You need to pause the VS debugger and not the simulator itself - this automatically pauses the simulator and then the Watch Window will work.

Regards

Mark

Offline kb1gtt

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
Re: AIS226DS / MOD-SMB380 I2C evaluation on LPC2378-STK
« Reply #34 on: May 29, 2010, 10:40:24 AM »
I see it now, I hadn't noticed that when I ran the simulator, the debugger popped up a watch window. I was thinking the watch window was the simulator. I see it now and I can look at these nitty gritties.

Thanks for the help.

Offline kb1gtt

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
Re: AIS226DS / MOD-SMB380 I2C evaluation on LPC2378-STK
« Reply #35 on: May 29, 2010, 01:26:46 PM »
I'm now looking at the registers and I think I found what you meant by there isn't a hardware driver for the 23XX chip. It appears it isn't defined in the LPC23XX.h or simLPC23XX.h. So I changed simLPC23XX.h to be like this.
Code: [Select]
unsigned long TER;
unsigned long PWM1MR; // ADDED BY JAH
unsigned long PWM1PCR; // added by jah
} LPC23XX_UART;
And LPC23XX.h looks like this.
Code: [Select]
#define U1TER                            *(volatile unsigned long*)(UART_BLOCK_1 + 0x30) // Transmit Enable Register
#define PWM1MR *(unsigned long*)(UART_BLOCK_1 + 0x8048) // PWM mod by JAH
#define PWM1PCR *(unsigned long*)(UART_BLOCK_1 + 0x804C) // PWM mod by JAH
Then I added this to application.c
Code: [Select]
PINSEL3 |=  1<<21;
PCONP |= 1<<6;
PCLKSEL0 |= 1<<12;
PWM1MR = 0xffffffff;
When I pause the debugger, ucLPC23xx.ucSimUart1 shows me both the PWM1MR and PWM1PCR as 0x00000000. That makes sense for PWM1PCR because it's default at boot is 0, and I appears utasker isn't changing that to something different. However, I wrote F's to PWM1MR so I expected to read back at a different value. Can I add registers like I have to the simulation, or is there other work that has to happen behind the scenes. Perhaps I need to add something to simLPC23XX.c?

Offline kb1gtt

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
Re: AIS226DS / MOD-SMB380 I2C evaluation on LPC2378-STK
« Reply #36 on: August 12, 2010, 11:13:08 AM »
I stepped away from this for a bit and I'm getting back into it again. I'm still having trouble figuring out how to see contents of registers that do not appear to be in LCP23XX.h. I'm looking to set the PWM 1.6 for the LCD such that I can dim the display on my LPC2378-STK dev board. Registers like PCONP and PINSEL3 work great. I wrote to them, and verified they work via the watch window. Also the simulator notes that pin is now PWM1.6, so it's looking great. However, I need to work with the below noted registers and I don't know how to set or verify bits of those registers.

From the UM10211 data sheet, I'm looking at PWM1TCR found on page 549, and PWM1MCR found on 550. The don't appear to be in the LPC23XX.h file, I've also looked under the timer section, and no dice. They start at 0xE001 8000 and it appears that UART_BLOCK_1 is 0xE001 0000, so I added the lines noted in the above thread to the watch window. This did not work, it would appear they are not supported in the dirver.c file. Right now it would appear that the PWM for this chip is not currently developed and falls outside of the memory range managed by the simulator. I may be wrong with that. My next attempt was to make it display on the physical LCD. However, I'm having some trouble getting that to work as well.

Is there a recommended way to view the contents of registers like PWM1TCR - 0xE001 8004 and PWM1MR - 0xE001 8048 ?

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3056
    • View Profile
    • uTasker
Re: AIS226DS / MOD-SMB380 I2C evaluation on LPC2378-STK
« Reply #37 on: August 12, 2010, 09:25:56 PM »
Hi

Any modules not yet build into the simulator cannot be accessed when simulating. This doesn't mean that they can not be used on the target though - just put code accessing the registers in a region using:
#ifndef _WINDOWS
...
#endif


I have nevertheless recently added PWM module support for the LPC23XX/LPC24XX. I will send you the latest LPC23XX.c and LPC23XX.h files by email as reference. For the simulator to be able to use them there are also changes to simLPC23XX.h also sent as reference.

I have been using this to control the contrast of an LCD (the same technique as required to control the display back-light intensity. Therefore here are a few details that should help you integrate it into your project.

1) The interface uses the timer interface (in fact the LPC21XX also supports PWM on the general purpose timers and use this interface already - it thus remains very similar, even if it uses a different module for the work):

static void fnSetContrast(void)
{
    TIMER_INTERRUPT_SETUP timer_setup = {0};                             // PWM Timer Init Struct
   timer_setup.int_type = TIMER_INTERRUPT;                              // timer setup type
    timer_setup.int_priority = 0;
    timer_setup.int_handler = 0;                                         // no interrupts used
    timer_setup.timer_reference = PWM1;                                  // use PWM module
    timer_setup.timer_mode  = (TIMER_PWM_1 | PWM_OUTPUT_PORT_1);         // use PWM channel 1 on port 1 output location
    timer_setup.timer_value = TIMER_US_DELAY(TIMER_FREQUENCY_VALUE(10000));// 10000 Hz contrast frequency
    timer_setup.pwm_value   = _PWM_PERCENT(temp_pars->temp_parameters.ucGLCDContrastPWM, timer_setup.timer_value); // contrast as PWM value
    fnConfigureInterrupt((void *)&timer_setup);                          // configure PWM output for contrast control
}


Note that PWM1 must be used with the LPC23XX since it doesn't have PWM0 (as the LPC24XX does).
TIMER_PWM_1 | PWM_OUTPUT_PORT_1 means that PWM channel 1 is used (there are 6 but they all operate from a single timer counter) and its output is to be connected on port 1. The PWM outputs can usually be mapped to several possible pins on different ports. [This is in fact P1.18 on the LPC23xx]]

2) The define SUPPORT_PWM_MODULE should be set to enable the driver code. The interface then powers up the PWM module, configures the pin, sets the timer base frequency (10kHz in the example above) and sets the PWM value (set using either _PWM_PERCENT() or _PWM_TENTH_PERCENT())

3) The PWM module can be used for generating more complex signals but the interface just sets standard PWM as it is.

4) The simulator will allow checking the code (stepping), the register values and the port pins but it won't generate any signals.

Good luck

Regards

Mark

Offline kb1gtt

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
Re: AIS226DS / MOD-SMB380 I2C evaluation on LPC2378-STK
« Reply #38 on: August 14, 2010, 12:20:22 PM »
Great, and again you were very helpful.

It currently shows PWM in the watch window, and allows me to verify the different bits. Lots of things look good, but I'm still not getting the PWM I expect. Perhaps my issue is that I don't fully understand the PWM_PERCENT call.

I used the the original LPC23XX.c and LPC23XX.h files then added the PWM sections of the files you sent along separately. I used the newer simLPC23XX.h with out compile problems. It now compiles and appears to work.

I don't know exactly how to use the temp_parameters.ucGLCDContrastPWM noted above, so I changed that line to be like this.
Code: [Select]
timer_setup.pwm_value   = _PWM_PERCENT(50,timer_setup.timer_value);//temp_pars->temp_parameters.ucGLCDContrastPWM, timer_setup.timer_value); // contrast as PWM valueI was aiming for a hard coded 50% PWM. I then called this function from in application.c under fnApplication. I'm probably calling this far more often than is required.

From the watch window I see

      PWMIR   0x00000000   unsigned long
      PWMTCR   0x00000009   unsigned long
      PWMTC   0x00000000   unsigned long
      PWMPR   0x00000000   unsigned long
      PWMPC   0x00000000   unsigned long
      PWMMCR   0x00000002   unsigned long
      PWMMR0   0x00000708   unsigned long
      PWMMR1   0x00000000   unsigned long
      PWMMR2   0x00000000   unsigned long
      PWMMR3   0x00000000   unsigned long
      PWMCCR   0x00000000   unsigned long
      PWMCR0   0x00000000   unsigned long
      PWMCR1   0x00000000   unsigned long
      PWMCR2   0x00000000   unsigned long
      PWMCR3   0x00000000   unsigned long
      ulRes0   0x00000000   unsigned long
      PWMMR4   0x00000000   unsigned long
      PWMMR5   0x00000000   unsigned long
      PWMMR6   0x00000000   unsigned long
      PWMPCR   0x00004000   unsigned long
      PWMLER   0x00000041   unsigned long
+      ulRes1   0x0054ad5c   unsigned long [7]
      PWMCTCR   0x00000000   unsigned long

These appear to me like channel 6 is set to PWM output, I believe that PWMMR6 indicates it's set to a 0% duty. This makes since as the LCD is dark, which leads me to believe that I'm not using PWM_PERCENT correctly. I've tried a handful of values large, small, hex, ect. PWMMR6 keeps coming back as 0. Perhaps I buggered something when I modified the LPC23XX files, I'm not sure. I searched for PWM_PERCENT to try and verify what it's expecting, but I didn't manage to find it. Just a define and a couple places where it's called.

Am I using PWM_PERCENT correctly? Is PWMMR indicating the duty?

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3056
    • View Profile
    • uTasker
Re: AIS226DS / MOD-SMB380 I2C evaluation on LPC2378-STK
« Reply #39 on: August 14, 2010, 02:17:32 PM »
Hi

The use of PWM_PERCENT(pwm, frequency) is with a first value between 0 and 100% and then the base frequency.
Eg. to set 65% PWM (65% '1', 35% '0') running at 5kHz this would be

PWM_PERCENT(65, TIMER_US_DELAY(TIMER_FREQUENCY_VALUE(5000)));

Note that the frequency value also uses its own macros since the idea is to allow the compiler to directly calculate the values to be written to the register when values are already known as fixed numbers (when variables are involved the calculation is performed at run time instead) - more details about frequency at the end.

In the example, the frequency value is directly timer_setup.timer_value since this is already the calculated frequency.

Since I only tested PWM1 - channel 1 I am not sure that there may be a problem when using channel 6. Therefore I tried simulating to see what happens in this case.

PWM1MR0 is the base frequency. In your case 0x00000708, which means that the timer is running at 10'000 Hz (assuming PCLK/4 and 72MHz PLL).
The PWMMR6 register controls channel 6 PWM so this should be set with the percentage value, but I also got the value 0x00000000. The value was in fact being written but to a location 3 long words after the PWMMR6 register. Presumably this would cause the PWM output to generate 0% duty cycle - i.e. output always '0'.

The source of the error is due to the fact that the PWM channel 1..3 and PWM channel 4..6 registers are not contiguous in the register memory. Therefore the following code is used to set a pointer to the register to be written:

        if (ulChannel >= 4) {
            ptrMatchRegister += (PWM1MR4_ADD - PWM1MR1_ADD);
        }


This code is however not correct for channels 4..6. It sets the pointer to PWM1MR4 but doesn't take into account that the channel is 3 higher than this reference. The correction (which I tested with all 6 channels) is:
        if (ulChannel >= 4) {
            ptrMatchRegister = (PWM1MR4_ADD - 3);
        }


This now sets the value 0x378 to PWM1MR6 (50% case) which is the value expected. As long as the pin is correctly set up I would expect it to then work correctly.
I the case of Port 1 which should be P1.26. In this case of port 2 this should be P2.5. There is no output for port 3.
The simulator shows P1.26 in the port 1 case as PWM1.6 so this looks good.

Regards

Mark



Note about frequency
===============

TIMER_US_DELAY(TIMER_FREQUENCY_VALUE(5000))

This uses two macros.
TIMER_FREQUENCY_VALUE(5000) converts the frequency into a period (i.e. 1/f) in us. In this case 200us is the period of 5kHz.
TIMER_US_DELAY(200) is then the value required in the timer match register to achieve a match after 200us and subsequently an output frequency of 5kHz/2 when the match causes an output pin to be toggled. This value is HW dependent and also processor frequency dependent. In the case of the LPC23XX running at 72MHz PLL and PCLK/4 clocking the timer module the match value is 0x708.

The match value used by PWM is a percentage of the period and so its calculation also requires the period to be known. That is why the period value is also passed to the PWM macro. A 50% duty cycle if therefore simply the period value/2, which can then also directly be written to the HW register.



Offline kb1gtt

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
Re: AIS226DS / MOD-SMB380 I2C evaluation on LPC2378-STK
« Reply #40 on: August 14, 2010, 06:40:33 PM »
The correction (which I tested with all 6 channels) is:
Great and thanks. This now works both in the simulator/watch window, as well as the proto board. Here are what I measured for PWM and current draw.

when at 100%, it measures 203ma, and is very bright
when at     0%, it measures 159ma, and is very dim
when at    20% it measures 160ma, and is very dim
when at   30%, it measures 172ma, and is reasonably bright
when at   35%, it measures 196ma, and is very bright, but not as much as

So the range for LCD appears to be around 25% to 35%, with 30% being good enough for indoor applications.

I guess it's now time to get back to the SPI stuff.

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3056
    • View Profile
    • uTasker
Re: AIS226DS / MOD-SMB380 I2C evaluation on LPC2378-STK
« Reply #41 on: August 14, 2010, 08:43:33 PM »
Hi

I would try also with lower switching rates (100..200Hz should be OK for back-light since it should not be detected as flicker by the eye).

I would expect the brightness to be more linear with PWM and it may be that the faster switching rate is causing problems with the semiconductor switch - it may not be saturating correctly (?).

I used 10kHz for my contrast control since I was filtering the PWM signal to a DC control value with an RC and 10kHz requires a smaller C - for direct switching 10kHz is possibly a bit fast.

Regards

Mark

Offline kb1gtt

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
Re: AIS226DS / MOD-SMB380 I2C evaluation on LPC2378-STK
« Reply #42 on: August 14, 2010, 11:04:53 PM »
Great, the 200hz works well, and 100hz has flicker. At 30% PWM it still draws 172ma. I haven't tried the other PWM rates yet.

I was digging into the LCD PWM in an attempt to resolve a problem I'm seeing. Unfortunately dimming the LCD didn't fix the problem, so perhaps this problem is sourced from somewhere else. The problem happens every 6.5 seconds when the proto board appears to reboot. The screen goes blank briefly and it appears to start the code again.

I had assumed this was due to the my supply being limited to 200ma via ARM-USB-OCD programmer device, and that the device may have been smart enough to notice I was drawing 203 ma when the LCD was on. Now I'm a fair bit under the max rating, and I'm still seeing this issue. I'm beginning to wonder if it might be a watch dog issue.

Are there any suggested areas where I should look to figure out why it might be rebooting every 6.5 seconds or so? My multimeter is telling me the min voltage drops to 4.77v while the normal voltage reads as 4.80v. So I don't think it's a power supply issue at this point.

Offline kb1gtt

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
Re: AIS226DS / MOD-SMB380 I2C evaluation on LPC2378-STK
« Reply #43 on: August 16, 2010, 03:19:11 AM »
So it appears that great things happen to those that that can read....

I just re-found the uTaskerV1.4_user_guide.pdf section 5 about creating your own task. I followed those great instructions then copied my code into this new task and the rebooting issue is no longer. I'm currently learning more about how tasks are handled, and following the examples, ect.


Offline kb1gtt

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
Re: AIS226DS / MOD-SMB380 I2C evaluation on LPC2378-STK
« Reply #44 on: August 19, 2010, 11:21:07 AM »
I just ran into a bit of a bugger. Flash magic was pointing to programming uTaskerV1.4.hex which  hasn't  been modified since the 15th. It appears that for some reason Visual Studio changed, and is compiling uTaskerBM.hex. I guess I'll have to go look over my configs. This BM version doesn't run on my proto board. However the simulator is working just fine. Could this be part of the recently modified simLPC23XX.h?

I see config.h is still set to #define OLIMEX_LPC2378_STK. A quick look down the project properties didn't cause anything to jump out at me. I'm not sure why the hex file changed, and it's time again to head out for the bump and grind. So until later this evening, I'll ponder what is going on.