microcontroller programming

Hello everyone..
I am doing a project on brushless dc motor control using Atmel32 UC3C microcontroller.
I have just started learning microcontroller programming and I am stuck at a point.
I am obtaining a waveform at PWM pins and I want an LED to follow this waveform i.e. Led lights up when waveform goes high n vice versa. Can anyone please tell me how to do that?

Alternatively I want an LED to follow a waveform given at an input pin (J41).
I have been stuck here for days and I would really appreciate some help. Thank you😀

Replies

  • Harshad Italiya
    Harshad Italiya
    Means you want to write the routine for PWM?
  • aastha.kanwar
    aastha.kanwar
    No right now I just want a command using which I can control LED as per my wish.
    For eg using command
    gpio_toggle_pin(LED0_GPIO)
    i can toggle LED0 acc to system clock.
    Similarly I want a command using which I can toggle LED acc to some other waveform (having different frequency and duty ratio)
  • Harshad Italiya
    Harshad Italiya
    Means you have PWM as input and want to interface LED with that signal right?
  • aastha.kanwar
    aastha.kanwar
    yes..right!!
  • Harshad Italiya
    Harshad Italiya
    Okey you can do something like this
    Suppose your PWM is connected with Pin number 20 and LED is at pin number 21

    then simply write code in which you are checking the status of the input pin and according to that set the status of output pin where you have connected LED.

    like

    if(pin number 20 is high) make pin number 21 high
    else check pin number 20 is Low make pin number 21 Low.
  • aastha.kanwar
    aastha.kanwar
    Thank you so much..
    But i think this is somewhat what I am already trying..
    I think maybe because i've just started learning programming, I am doing something wrong with formats or something..


    #include
    #include
    #include
    #include
    #define INP_PIN AVR32_PIN_PB27
    #define INP_FUNCTION 0
    #define GPIO_DIR_INPUT (0 << 0)
    int x;

    int main(void)
    {
    sysclk_init();
    board_init();
    gpio_enable_module_pin(INP_PIN, INP_FUNCTION);

    x = gpio_get_pin_value (INP_PIN);


    if (x == 1)
    gpio_set_gpio_pin(LED1_GPIO);
    else if (x == 0)
    gpio_clr_gpio_pin(LED1_GPIO);


    while (1);
    }
  • Harshad Italiya
    Harshad Italiya
    Yes you have to make the Pin in OUTPUT direction on which you have connected LED. and in this code i am not able to find such intstruction which makes PIN as OUTPUT direction. Please do that. and post the response is it working or not.
  • aastha.kanwar
    aastha.kanwar
    I have not externally connected LED, its actually built in the chip. And I looked but I can't find any instruction to declare this pin as output, maybe its not required but I am sorry I don't know.
  • Harshad Italiya
    Harshad Italiya
    aastha.kanwar
    I have not externally connected LED, its actually built in the chip. And I looked but I can't find any instruction to declare this pin as output, maybe its not required but I am sorry I don't know.
    It may not required as by default it may be as Output only. can you let me know which board you are using?
  • aastha.kanwar
    aastha.kanwar
    Atmel32 UC3C EK
    I think it is the latest board released by Atmel
  • Harshad Italiya
    Harshad Italiya
    aastha.kanwar
    Atmel32 UC3C EK
    I think it is the latest board released by Atmel
    can you give me its link.
  • Harshad Italiya
    Harshad Italiya
    I mean Circuit diagram of the Kit or Schematic.
  • aastha.kanwar
    aastha.kanwar
    #-Link-Snipped-#]Atmel Corporation - Atmel AVR 8- and 32-bit - Automotive AVR -
    the above link has all the documents..

    otherwise the link for schematics is
    #-Link-Snipped-#

    Here r other user guides :
    #-Link-Snipped-#
    #-Link-Snipped-#

    thrs actually a big 1200 page user guide which is a combination of all these but i couldnt find it online..
  • Harshad Italiya
    Harshad Italiya
    Hey,
    I am not able to find the LED in this Schematic. 😔
  • aastha.kanwar
    aastha.kanwar
    hey m srry this is the one i wanted to send instead of first one..

    #-Link-Snipped-#

    even I coulnt find LEDs in schematic..i thought maybe it is because I am a newbie
    anyways you can find them in the last document..there are four LEDs under the screen
  • Harshad Italiya
    Harshad Italiya
    aastha.kanwar
    hey m srry this is the one i wanted to send instead of first one..

    #-Link-Snipped-#


    even I coulnt find LEDs in schematic..i thought maybe it is because I am a newbie
    anyways you can find them in the last document..there are four LEDs under the screen
    Okey then please check that LED is connected at which pin?
  • aastha.kanwar
    aastha.kanwar
    LED0_GPIO AVR32_PIN_PA08 8
    LED1_GPIO AVR32_PIN_PD23 119
    LED2_GPIO AVR32_PIN_PC13 77
    LED3_GPIO AVR32_PIN_PD22 118

    and I also found LEDs on page 6 of schematic
  • Harshad Italiya
    Harshad Italiya
    I have not checked the Pdf, But now i want to say you that as all these 8,119,77,118 are connected with LED. there should be function which sets that pin high like as you are using the function to toggle the LED.

    hey,
    i found something wrong here.
    x=gpio_get_pin_value(INP_PIN);


    if(x==1)
    gpio_set_gpio_pin(LED1_GPIO);
    elseif(x==0)
    gpio_clr_gpio_pin(LED1_GPIO);


    while(1);
    }

    can you tell me what value you are receiving after the instruction marked in red. i mean what is the value of X? i think you have debugger then you can put breakpoint there.

You are reading an archived discussion.

Related Posts

Learn about the Cropped Surface feature in AutoCAD Civil 3D 2011. [video=youtube;Ej8dFrQrdGg]https://www.youtube.com/watch?v=Ej8dFrQrdGg[/video]
This video shows on how to Create a Surface From a Point Group. [video=youtube;1eex95i0j8Y]https://www.youtube.com/watch?v=1eex95i0j8Y[/video]
Here i am with some thing different idea😒, just discuss on following points. 1) What is the domain registration & which is the best at this time in market? 2)...
Green giants? The UK is working with India and China to develop green technologies, belying the perception of Asia as a runaway threat to the climate Read more: Green giants?...
Hi! I'm a mechanical engineering undergraduate at University of Science Malaysia and I will be entering into my final year in September. Currently doing my internship. I was given an...