CrazyEngineers
  • microcontroller programming

    Updated: Oct 25, 2024
    Views: 1.1K
    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😀
    0
    Replies
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • Harshad Italiya

    MemberMay 18, 2011

    Means you want to write the routine for PWM?
    Are you sure? This action cannot be undone.
    Cancel
  • aastha.kanwar

    MemberMay 18, 2011

    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)
    Are you sure? This action cannot be undone.
    Cancel
  • Harshad Italiya

    MemberMay 18, 2011

    Means you have PWM as input and want to interface LED with that signal right?
    Are you sure? This action cannot be undone.
    Cancel
  • aastha.kanwar

    MemberMay 18, 2011

    yes..right!!
    Are you sure? This action cannot be undone.
    Cancel
  • Harshad Italiya

    MemberMay 18, 2011

    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.
    Are you sure? This action cannot be undone.
    Cancel
  • aastha.kanwar

    MemberMay 18, 2011

    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 <compiler.h>
    #include <sysclk.h>
    #include <board.h>
    #include <gpio.h>
    #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);
    }
    Are you sure? This action cannot be undone.
    Cancel
  • Harshad Italiya

    MemberMay 18, 2011

    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.
    Are you sure? This action cannot be undone.
    Cancel
  • aastha.kanwar

    MemberMay 18, 2011

    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.
    Are you sure? This action cannot be undone.
    Cancel
  • Harshad Italiya

    MemberMay 18, 2011

    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?
    Are you sure? This action cannot be undone.
    Cancel
  • aastha.kanwar

    MemberMay 18, 2011

    Atmel32 UC3C EK
    I think it is the latest board released by Atmel
    Are you sure? This action cannot be undone.
    Cancel
  • Harshad Italiya

    MemberMay 18, 2011

    aastha.kanwar
    Atmel32 UC3C EK
    I think it is the latest board released by Atmel
    can you give me its link.
    Are you sure? This action cannot be undone.
    Cancel
  • Harshad Italiya

    MemberMay 18, 2011

    I mean Circuit diagram of the Kit or Schematic.
    Are you sure? This action cannot be undone.
    Cancel
  • aastha.kanwar

    MemberMay 19, 2011

    #-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..
    Are you sure? This action cannot be undone.
    Cancel
  • Harshad Italiya

    MemberMay 19, 2011

    Hey,
    I am not able to find the LED in this Schematic. 😔
    Are you sure? This action cannot be undone.
    Cancel
  • aastha.kanwar

    MemberMay 19, 2011

    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
    Are you sure? This action cannot be undone.
    Cancel
  • Harshad Italiya

    MemberMay 19, 2011

    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?
    Are you sure? This action cannot be undone.
    Cancel
  • aastha.kanwar

    MemberMay 19, 2011

    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
    Are you sure? This action cannot be undone.
    Cancel
  • Harshad Italiya

    MemberMay 19, 2011

    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.
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register