Show Posts
Pages: [1] 2
1  Using Arduino / Microcontrollers / Re: Arduino Uno with a 32-bit ARM Cortex-M0 in 28 pin DIL package on: November 20, 2012, 02:29:28 am
A different question,
Can a source code (including the libraries) written in LPC Xpresso be ported, preferably in an easy manner, to Keil uVision4 for ARM?
Reason: LPC Xpresso does not have a simulator while Keil has so the code can be debugged without using the real hardware.
2  Using Arduino / Microcontrollers / Re: Arduino Uno with a 32-bit ARM Cortex-M0 in 28 pin DIL package on: November 20, 2012, 01:55:30 am
I am seeing that MikroElektronika site has: C, Basic and Pascal compilers for ARM, PIC, PIC32, AVR, 8051.
see: http://www.mikroe.com/forum/
The question is, are these people serious? They seem to have all major compilers possible for all major microcontrollers on the market.

Example:
Code written for mikroBasic ARM compiler
Code:
' * Project name:
'     Pwm_Demo (Demo on using mikroE's PWM library functions)
' * Copyright:
'     (c) Mikroelektronika, 2011.
' * Revision History:
'     20110105:
'       - initial release;
' * Description:
'     This is a simple demonstration of PWM library, which is being used for
'     control of the ARM's PWM module. The module is initialized and started,
'     after which the PWM's Duty Ratios can be adjusted by means of 4 buttons
'     connected to pins PA0, PA1, PA2 and PA3. The changes can be monitored on the PWM
'     output pins (PB0 and PB2).
' * Test configuration:
'     MCU:             LM3S9B95
'                      http://www.ti.com/lit/ds/symlink/lm3s9b95.pdf
'     Dev.Board:       EasyMx v7 for STELLARIS(R) ARM(R)
'                      http://www.mikroe.com/eng/products/view/792/easymx-pro-v7-for-stellaris-arm/
'     Oscillator:      XT-PLL, 80.000MHz
'     Ext. Modules:    None.
'     SW:              mikroBasic PRO for ARM
'                      http://www.mikroe.com/eng/products/view/753/mikrobasic-pro-for-arm/
' * NOTES:
'   - Turn off all PORT LEDs except PORTB at SW15. (board specific)
'   - Pull-down PORTA at SW1, and put SW16.1 in VCC position (board specific)

program Pwm_Demo
dim current_duty, old_duty, current_duty1, old_duty1 as word
    pwm_period1, pwm_period2 as word

sub procedure InitMain()
  GPIO_Digital_Input (@GPIO_PORTA, _GPIO_PINMASK_ALL) ' configure PORTA pins as input
end sub

main:
  InitMain()
  current_duty  = 100                         ' initial value for current_duty
  current_duty1 = 100                         ' initial value for current_duty1

  pwm_period1 = PWM_CCP0_Init(5000, @_GPIO_MODULE_CCP0_B0)
  pwm_period2 = PWM_CCP3_Init(5000, @_GPIO_MODULE_CCP3_B2)

  PWM_CCP0_Start()
  PWM_CCP3_Start()

  PWM_CCP0_Set_Duty(current_duty,  _PWM_INVERTED_DISABLE)  ' Set current duty for PWM_CCP0
  PWM_CCP3_Set_Duty(current_duty1, _PWM_INVERTED_DISABLE)  ' Set current duty for PWM_CCP3

  while (TRUE)                               ' endless loop
    if GPIO_PORTA_DATA.B0 = 1 then           ' button on RA0 pressed
      Delay_ms(1)
      current_duty = current_duty + 5        ' increment current_duty
      if (current_duty > pwm_period1) then   ' if we increase current_duty greater then possible pwm_period1 value
        current_duty = 0                     ' reset current_duty value to zero
      end if
      PWM_CCP0_Set_Duty(current_duty,  _PWM_INVERTED_DISABLE) ' set newly acquired duty ratio
    end if

    if GPIO_PORTA_DATA.B1 = 1 then           ' button on RA1 pressed
      Delay_ms(1)
      current_duty = current_duty - 5        ' decrement current_duty
      if (current_duty > pwm_period1) then   ' if we decrease current_duty greater then possible pwm_period1 value (overflow)
        current_duty = pwm_period1           ' set current_duty to max possible value
      end if
      PWM_CCP0_Set_Duty(current_duty,  _PWM_INVERTED_DISABLE) ' set newly acquired duty ratio
    end if

    if GPIO_PORTA_DATA.B2 = 1 then           ' button on RA2 pressed
      Delay_ms(1)
      current_duty1 = current_duty1 + 5      ' increment current_duty1
      if (current_duty1 > pwm_period2) then  ' if we increase current_duty1 greater then possible pwm_period2 value
        current_duty1 = 0                    ' reset current_duty1 value to zero
      end if
      PWM_CCP3_Set_Duty(current_duty1, _PWM_INVERTED_DISABLE)       ' set newly acquired duty ratio
    end if

    if GPIO_PORTA_DATA.B3 = 1 then           ' button on RA3 pressed
      Delay_ms(1)
      current_duty1 = current_duty1 - 5      ' decrement current_duty1
      if (current_duty1 > pwm_period2) then  ' if we decrease current_duty1 greater then possible pwm_period1 value (overflow)
        current_duty1 = pwm_period2          ' set current_duty to max possible value
      end if
      PWM_CCP3_Set_Duty(current_duty1, _PWM_INVERTED_DISABLE)
    end if

    Delay_ms(1)                              ' slow down change pace a little
  wend
end.
3  Using Arduino / Microcontrollers / Re: Arduino Uno with a 32-bit ARM Cortex-M0 in 28 pin DIL package on: November 19, 2012, 08:08:03 pm
The ide does not hide anything: you can always code the mcu by writing to the registers.
However, in this case, they use a set of libraries from nxp to operate the peripherals. That's not unusual: ST has a set of its own libraries.
Without those libraries working with ARM peripherals is really not practical.

If indeed one have to write all these lines of code to initialize a timer I imagine that not many people would dare to attack ARMs.
Code:
/******************************************************************************
** Function name: init_timer
**
** Descriptions: Initialize timer, set timer interval, reset timer,
** install timer interrupt handler
**
** parameters: timer number and timer interval
** Returned value: None
**
******************************************************************************/
void init_timer32(uint8_t timer_num, uint32_t TimerInterval)
{
  if ( timer_num == 0 )
  {
    /* Some of the I/O pins need to be carefully planned if
    you use below module because JTAG and TIMER CAP/MAT pins are muxed. */
    LPC_SYSCON->SYSAHBCLKCTRL |= (1<<9);
    LPC_IOCON->PIO1_5 &= ~0x07; /*  Timer0_32 I/O config */
    LPC_IOCON->PIO1_5 |= 0x02; /* Timer0_32 CAP0 */
    LPC_IOCON->PIO1_6 &= ~0x07;
    LPC_IOCON->PIO1_6 |= 0x02; /* Timer0_32 MAT0 */
    LPC_IOCON->PIO1_7 &= ~0x07;
    LPC_IOCON->PIO1_7 |= 0x02; /* Timer0_32 MAT1 */
    LPC_IOCON->PIO0_1 &= ~0x07;
    LPC_IOCON->PIO0_1 |= 0x02; /* Timer0_32 MAT2 */
#ifdef __JTAG_DISABLED
    LPC_IOCON->JTAG_TDI_PIO0_11 &= ~0x07;
    LPC_IOCON->JTAG_TDI_PIO0_11 |= 0x03; /* Timer0_32 MAT3 */
#endif
#if CONFIG_TIMER32_DEFAULT_TIMER32_0_IRQHANDLER==1
    timer32_0_counter = 0;
    timer32_0_capture = 0;
#endif //TIMER32_0_DEFAULT_HANDLER
    LPC_TMR32B0->MR0 = TimerInterval;
#if TIMER_MATCH
LPC_TMR32B0->EMR &= ~(0xFF<<4);
LPC_TMR32B0->EMR |= ((0x3<<4)|(0x3<<6)|(0x3<<8)|(0x3<<10)); /* MR0/1/2/3 Toggle */
#else
/* Capture 0 on rising edge, interrupt enable. */
LPC_TMR32B0->CCR = (0x1<<0)|(0x1<<2);
#endif
    LPC_TMR32B0->MCR = 3; /* Interrupt and Reset on MR0 */

#if CONFIG_TIMER32_DEFAULT_TIMER32_0_IRQHANDLER==1
    /* Enable the TIMER0 Interrupt */
    NVIC_EnableIRQ(TIMER_32_0_IRQn);
#endif
  }
  else if ( timer_num == 1 )
  {
    /* Some of the I/O pins need to be clearfully planned if
    you use below module because JTAG and TIMER CAP/MAT pins are muxed. */
    LPC_SYSCON->SYSAHBCLKCTRL |= (1<<10);
#ifdef __JTAG_DISABLED
    LPC_IOCON->JTAG_TMS_PIO1_0  &= ~0x07; /*  Timer1_32 I/O config */
    LPC_IOCON->JTAG_TMS_PIO1_0  |= 0x03; /* Timer1_32 CAP0 */
    LPC_IOCON->JTAG_TDO_PIO1_1  &= ~0x07;
    LPC_IOCON->JTAG_TDO_PIO1_1  |= 0x03; /* Timer1_32 MAT0 */
    LPC_IOCON->JTAG_nTRST_PIO1_2 &= ~0x07;
    LPC_IOCON->JTAG_nTRST_PIO1_2 |= 0x03; /* Timer1_32 MAT1 */
    LPC_IOCON->ARM_SWDIO_PIO1_3  &= ~0x07;
    LPC_IOCON->ARM_SWDIO_PIO1_3  |= 0x03; /* Timer1_32 MAT2 */
#endif
    LPC_IOCON->PIO1_4 &= ~0x07;
    LPC_IOCON->PIO1_4 |= 0x02; /* Timer0_32 MAT3 */

#if CONFIG_TIMER32_DEFAULT_TIMER32_1_IRQHANDLER==1
    timer32_1_counter = 0;
    timer32_1_capture = 0;
#endif //TIMER32_1_DEFAULT_HANDLER

    LPC_TMR32B1->MR0 = TimerInterval;
#if TIMER_MATCH
LPC_TMR32B1->EMR &= ~(0xFF<<4);
LPC_TMR32B1->EMR |= ((0x3<<4)|(0x3<<6)|(0x3<<8)|(0x3<<10)); /* MR0/1/2 Toggle */
#else
/* Capture 0 on rising edge, interrupt enable. */
LPC_TMR32B1->CCR = (0x1<<0)|(0x1<<2);
#endif
    LPC_TMR32B1->MCR = 3; /* Interrupt and Reset on MR0 */

#if CONFIG_TIMER32_DEFAULT_TIMER32_1_IRQHANDLER==1
    /* Enable the TIMER1 Interrupt */
    NVIC_EnableIRQ(TIMER_32_1_IRQn);
#endif
  }
  return;
}
Maybe not all the code above is necessary for a particular application. I do not know.

There is another problem, sometimes you have to change the parameters of a timer on the run as fast as possible between two events that are 10-20 clock cycles apart.
It seems like functions as "init_timer32" need more than 20 clk. ticks. Is there workarounds?
4  Using Arduino / Microcontrollers / Re: Arduino Uno with a 32-bit ARM Cortex-M0 in 28 pin DIL package on: November 19, 2012, 07:10:16 pm
I have not studied it too much but the LPC Xpresso IDE, designed for ARMs produced by NXP, seems quite easy to work with.

The IDE hides the internal registers and you work mainly with easy to understand functions that set timers, IO ports, etc..
However, there may be traps, complications. LPC Xpresso IDE does not have a simulator, for instance, like Keil. You need the real hardware to test your code.

LPC Xpresso code example:
Code:
/****************************************************************************
 *   $Id:: PWM16_32test.c 3635 2010-06-02 00:31:46Z usb00423                $
 *   Project: NXP LPC11xx 16-bit/32-bit PWM example
 *
 *   Description:
 *     This file contains PWM test modules, main entry, to test PWM APIs.
 *
 ****************************************************************************
 * Software that is described herein is for illustrative purposes only
 * which provides customers with programming information regarding the
 * products. This software is supplied "AS IS" without any warranties.
 * NXP Semiconductors assumes no responsibility or liability for the
 * use of the software, conveys no license or title under any patent,
 * copyright, or mask work right to the product. NXP Semiconductors
 * reserves the right to make changes in the software without
 * notification. NXP Semiconductors also make no representation or
 * warranty that such application will be suitable for the specified
 * use without further testing or modification.
****************************************************************************/

#include "driver_config.h"
#include "target_config.h"

#include "timer32.h"
#include "timer16.h"
#include "gpio.h"

extern volatile uint32_t timer32_0_counter;

volatile uint32_t period = 1000;  //48Khz PWM frequency

/* Main Program */

int main (void) {
/* Initialize 32-bits timer 0 */
init_timer32(0, TIME_INTERVAL);
enable_timer32(0);

/* Initialize the PWM in timer32_1 enabling match0 output */
init_timer32PWM(1, period, MATCH0);
setMatch_timer32PWM (1, 0, period/4);
enable_timer32(1);

/* Initialize the PWM in timer16_1 enabling match1 output */
init_timer16PWM(1, period, MATCH1, 0);
setMatch_timer16PWM (1, 1, period/8);
enable_timer16(1);

/* Enable AHB clock to the GPIO domain. */
LPC_SYSCON->SYSAHBCLKCTRL |= (1<<6);

/* Set port 2_0 to output */
GPIOSetDir( 2, 0, 1 );

while (1)                                /* Loop forever */
{
/* I/O configuration and LED setting pending. */
if ( (timer32_0_counter > 0) && (timer32_0_counter <= 50) )
{
GPIOSetValue( 2, 0, 0 );
}
if ( (timer32_0_counter > 50) && (timer32_0_counter <= 100) )
{
GPIOSetValue( 2, 0, 1 );
}
else
while ( timer32_0_counter < 100 ); //wait for
  timer32_0_counter = 0;
}
}

A nice feature I like is that LPC Xpresso displays explanations about a function, ex. init_timer32 (the meaning of parameters, etc.) if you glide the mouse cursor over its name.
5  Using Arduino / Microcontrollers / Re: Arduino Uno with a 32-bit ARM Cortex-M0 in 28 pin DIL package on: November 19, 2012, 12:27:39 pm
Mouser had 3907 chips LPC1114FN28/102 DIP on 15 Nov. 2012. Now, 4 days later they have 3899 in stock.
This microcontroller does not seem to have many clients.
6  Using Arduino / Microcontrollers / Re: Arduino Uno with a 32-bit ARM Cortex-M0 in 28 pin DIL package on: November 16, 2012, 07:41:02 pm
Also the ADC for LPC1114FN28/102 is at least 5 times faster than the one on Atmega328p, (for the ARM I am not seeing the maximum conversion time at full resolution which is needed for a more precise comparison).

ARM
The LPC1110/11/12/13/14/15 contain one ADC. It is a single 10-bit successive
approximation ADC with eight channels.
...
• Measurement range 0 V to VDD.
• 10-bit conversion time >= 2.44 us (up to 400 kSamples/s).


AVR
ATmega48PA/88PA/168PA/328P
Analog-to-Digital Converter

• 10-bit Resolution
• 13 - 260 μs Conversion Time
• Up to 76.9 kSPS (Up to 15 kSPS at Maximum Resolution)
7  Using Arduino / Microcontrollers / Re: Arduino Uno with a 32-bit ARM Cortex-M0 in 28 pin DIL package on: November 16, 2012, 01:22:50 pm
There is a comparison between ARM Cortex M0 and other controllers including AVR.
see: http://ics.nxp.com/literature/presentations/microcontrollers/pdf/cortex.m0.code.density.pdf
especially pages 41, 42, 43.
8  Using Arduino / General Electronics / Re: Atmega168 negative input protection on: November 16, 2012, 02:23:22 am
Build a Voltage divider, see:
http://www.psocdeveloper.com/forums/viewtopic.php?f=42&t=8573
Make Vcc=2V, do not add the capacitor. Ignore any value, you get from the ADC, between 0 and +1V, this is ignore any conversion < ADC resolution / 2.

However, improvements are needed because you lose resolution.
9  Using Arduino / Microcontrollers / Re: Arduino Uno with a 32-bit ARM Cortex-M0 in 28 pin DIL package on: November 16, 2012, 01:22:24 am
Somebody has already tried LPC1114FN28/102 DIP28 on a breadboard with a "blink a led" test code.
See: http://www.meatandnetworking.com/tutorials/lpc1114fn28-with-open-source-tools/ for all details.

The test just says that this ARM is relatively easy to use by hobbyists. However, it does not prove anything about the performance of LPC1114FN28/102 as compared with an Atmega328p, for example. If it is not 10 times faster, likely AVR funs will not abandon so easily their favorite microcontroller for it.
10  Using Arduino / Microcontrollers / Re: Arduino Uno with a 32-bit ARM Cortex-M0 in 28 pin DIL package on: November 15, 2012, 07:34:41 pm
I have searched for LPC1114FN28/102 DIP but Digikey does not have it in stock. However, it can be found at Mouser.
It means that LPC1114FN28/102 DIP has gained some market.
11  Using Arduino / Microcontrollers / Re: Robustness and long term reliability of Arduino boards and AVR chips on: November 12, 2012, 02:21:59 am
That's complete rubbish. There's no way Atmel would survive if that was true.
Are you clawson, the main moderator from avrfreaks?
12  Using Arduino / Microcontrollers / Re: Robustness and long term reliability of Arduino boards and AVR chips on: November 11, 2012, 05:23:23 pm
Yeah thats interesting too. I always wondered what chips industrial PLCs use. Do they use commercial ones manufactured by large fab houses or do they program their own controllers with FPGAs, ASICs, etc?
They use also FPGAs and ASICs on PLC boards but this does not mean they are implementing their own processors in ASICs. That would be highly inefficient as long as there are proven processors on the market with good compilers and IDE.
13  Using Arduino / Microcontrollers / Re: Robustness and long term reliability of Arduino boards and AVR chips on: November 11, 2012, 04:29:13 pm
Honestly, the 8 bit AVR controllers seem to be used mainly by hobbyists. I have looked for a list of professional devices that use AVRs but I found no convincing evidence they have serious applications in practice.
Regarding PICs, I have found some credible commercial devices, not related to hobbyists, that use them.

I am not aware of any PLC that makes use of 8 bit AVRs, maybe because the PLC designers do not want to become dependent of a single chip supplier (Atmel). PLCs use ARMs, 8051 or other processors that are produced by many manufacturers.
Also, 8 bit AVR are weak for industrial applications. You could hardly implement a serious modern PLC using AVRs.
14  Using Arduino / Microcontrollers / Re: Assistance needed programming the ATTiny84 with the Arduino Uno ATMega328P-PU. on: November 11, 2012, 04:07:08 pm
You bought the Attiny84 set to run with its internal RC oscillator.
Finally, without setting the Attiny84 to work with the 20 MHz Crystal, you attached the external oscillator and you programmed the controller.
How is it possible?

Likely your chip was already set for external crystal which is not its default state.
15  Using Arduino / Microcontrollers / Re: Assistance needed programming the ATTiny84 with the Arduino Uno ATMega328P-PU. on: November 09, 2012, 07:46:15 pm
I added 1 @ 20 mhz crystal and 2 @ 22 pF capacitors on XTAL1 XTAL2 which created an external AVR oscillator and now the bootloader for the ATTiny 84 ran successfully.
So, was your ATTiny 84 already set somehow by you to work with the external oscillator or you bought it configured for external oscillator?
Pages: [1] 2