Light won't blink!

Go To Last Post
6 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm trying to configure a custom board which uses a AT32UC3C0512C. The clock source is a 50 MHz digital oscillator (ASDMB-50.000MHZ-XY-T). I'm just trying to get a blinky code working. It builds fine and reaches the breakpoint I've set at the gpio_toggle_pin line consistently, but the light does not blink. I've used a scope on the pin and it is constant at ~1 V. I suspect there's a problem with my configuration code (I have no prior experience with AVR chips). One strange issue I ran into is that "OSC0_GAIN_VALUE" must be defined, even though I am using a digital oscillator. Here is my main code:

int main (void)
{

	sysclk_init();
	board_init();
	
	gpio_enable_gpio_pin(AVR32_PIN_PA08);
	
	while(1){
		gpio_toggle_pin(AVR32_PIN_PA08);
		delay_ms(200);
	}

}

user_board.h:

#ifndef USER_BOARD_H
#define USER_BOARD_H

#include <conf_board.h>


#define BOARD_OSC0_HZ           50000000
#define BOARD_OSC0_STARTUP_US   142000
#define BOARD_OSC0_IS_XTAL      false
#define BOARD_OSC32_HZ          32768
#define BOARD_OSC32_STARTUP_US  71000
#define BOARD_OSC32_IS_XTAL     false

#define OSC0_GAIN_VALUE      AVR32_SCIF_OSCCTRL0_GAIN_G3


#endif // USER_BOARD_H

conf_clock.h:

#ifndef CONF_CLOCK_H_INCLUDED
#define CONF_CLOCK_H_INCLUDED

//#define CONFIG_SYSCLK_INIT_CPUMASK  (1 << SYSCLK_SYSTIMER)
//#define CONFIG_SYSCLK_INIT_PBAMASK  (1 << SYSCLK_USART0)
//#define CONFIG_SYSCLK_INIT_PBBMASK  (1 << SYSCLK_HMATRIX)
//#define CONFIG_SYSCLK_INIT_HSBMASK  (1 << SYSCLK_MDMA_HSB)

//#define CONFIG_SYSCLK_SOURCE          SYSCLK_SRC_RCSYS
#define CONFIG_SYSCLK_SOURCE        SYSCLK_SRC_OSC0
//#define CONFIG_SYSCLK_SOURCE        SYSCLK_SRC_OSC1
//#define CONFIG_SYSCLK_SOURCE        SYSCLK_SRC_PLL0
//#define CONFIG_SYSCLK_SOURCE        SYSCLK_SRC_PLL1
//#define CONFIG_SYSCLK_SOURCE        SYSCLK_SRC_RC8M

/* Fbus = Fsys / (2 ^ BUS_div) */
#define CONFIG_SYSCLK_CPU_DIV         0
#define CONFIG_SYSCLK_PBA_DIV         0
#define CONFIG_SYSCLK_PBB_DIV         0
#define CONFIG_SYSCLK_PBC_DIV         0

//#define CONFIG_USBCLK_SOURCE        USBCLK_SRC_OSC0
//#define CONFIG_USBCLK_SOURCE        USBCLK_SRC_OSC1
#define   CONFIG_USBCLK_SOURCE        USBCLK_SRC_PLL0
//#define CONFIG_USBCLK_SOURCE        USBCLK_SRC_PLL1

/* Fusb = Fsys / USB_div */
#define CONFIG_USBCLK_DIV             1

#define CONFIG_PLL0_SOURCE            PLL_SRC_OSC0
//#define CONFIG_PLL0_SOURCE          PLL_SRC_OSC1
//#define CONFIG_PLL0_SOURCE          PLL_SRC_RC8M

/* Fpll0 = (Fclk * PLL_mul) / PLL_div */
#define CONFIG_PLL0_MUL               (48000000UL / BOARD_OSC0_HZ)
#define CONFIG_PLL0_DIV               1

//#define CONFIG_PLL1_SOURCE          PLL_SRC_OSC0
//#define CONFIG_PLL1_SOURCE          PLL_SRC_OSC1
//#define CONFIG_PLL1_SOURCE          PLL_SRC_RC8M

/* Fpll1 = (Fclk * PLL_mul) / PLL_div */
#define CONFIG_PLL1_MUL               (48000000UL / BOARD_OSC0_HZ)
#define CONFIG_PLL1_DIV               1

#endif /* CONF_CLOCK_H_INCLUDED */

I'm hoping one of you gurus can point out my (probably) obvious mistake(s)...

This topic has a solution.
Last Edited: Fri. Jun 15, 2018 - 01:09 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

No experience with AVR32 controllers, but:

 

are there no peripheral clocks that you need to configure ?

If you did, have you tripple checked that they are configured correctly?

 

can it be that you are toggling a pin so fast that the LED will not blink visibly?

measuring at the wrong pin? (try flipping a full port and see if pins do change)

 

Pin you want to toggle is not a special function pin that needs to be configured to be normal IO first before you can actually control it?

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The ASF gpio_enable_gpio_pin() enables the pin as a GPIO input
Have a look at gpio_configure_pin(,)
gpio_tgl_gpio_pin() will toggle the pin and has the side-effect of setting the pin as a GPIO output. (everytime)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

bubbzilla wrote:
I have no prior experience with AVR chips

So why did you choose an AVR32 - which always has been "niche" and is now pretty much obsolete?

 

https://www.avrfreaks.net/commen...

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

mikech wrote:
The ASF gpio_enable_gpio_pin() enables the pin as a GPIO input Have a look at gpio_configure_pin(,) gpio_tgl_gpio_pin() will toggle the pin and has the side-effect of setting the pin as a GPIO output. (everytime)

 

This was the problem, thanks. I see now that gpio_enable_gpio_pin has oderc instead of oders. It works after I replaced

gpio_enable_gpio_pin(AVR32_PIN_PA08);

with

AVR32_GPIO.port[0].oders = 1 << (8 & 0x1F);
AVR32_GPIO.port[0].gpers = 1 << (8 & 0x1F);

 

awneil wrote:
So why did you choose an AVR32 - which always has been "niche" and is now pretty much obsolete?

 

I'm a masters student and my research involves testing MCUs. This is one of many MCUs that I am testing.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

bubbzilla wrote:
my research involves testing MCUs. 

interesting. what's the goal of your project ?

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...