Burst firing PWM

General discussion on mikroPascal PRO for AVR.
Post Reply
Author
Message
PeterMcLeod
Posts: 14
Joined: 30 Aug 2013 10:07

Burst firing PWM

#1 Post by PeterMcLeod » 21 Nov 2019 00:38

I want to fire a spark generator using PWM. The circuit needs a 100 to 250mS burst at 25Khz with a variable duty.
I am using an ATxMEGA128A1U (MIkroelectronica Ready for XMEGA) and a MikroPascal for AVR compiler.
I have set up the parameters for the PWM as follows

PORTC_DIRSET := 0xff; // PWM is on PC0, set PORTC as output

PWM_C0_Init(25000, _PWM_SINGLE_SLOPE); //Frequency 25Khz
PWM_C0_Start(_CCA_CHANNEL); //Channel A on PORTC - PC0
PWM_C0_Set_Duty(Spark_duty,_PWM_NON_INVERTED,_CCA_CHANNEL); // Set PWM duty

My output is on PC0.
According to the help pages I have to 'Start' the PWM before declaring the duty. so my idea of starting the output, waiting for 100mS then 'Stopping' the output seems wrong. Could you help me please?
Also the help pages often give the code for ATMEGA rather than XMEGA so I have to dig to find the correct codes.
The help page mentions an example but one is not included with the XMEGA documentation.
thanks and regards
Peter

User avatar
stefan.filipovic
mikroElektronika team
Posts: 1135
Joined: 18 Dec 2018 10:30

Re: Burst firing PWM

#2 Post by stefan.filipovic » 21 Nov 2019 17:57

Hi Peter,

I'm not sure if I quite understand you correctly.

Is this what you are looking for?

Code: Select all

program PWM_test;

var current_duty : byte;

  begin
    PORTC_DIRSET := 0xFF;             // Set direction to be output

    PWM_C0_Init(25000,_PWM_SINGLE_SLOPE);
    PWM_C0_Start(0);
    PWM_C0_Set_Duty(current_duty, _PWM_NON_INVERTED, 0);      
    current_duty := 0x10;

    while TRUE do
      begin
        PWM_C0_Start(0);
        Delay_ms(100);
        PWM_C0_Stop(0);
        PORTC_OUTCLR := 0xFF;
        Delay_ms(1000);
      end;                    // Endless loop
  end.
Kind regards,
Stefan Filipović

Post Reply

Return to “mikroPascal PRO for AVR General”