CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

[SOLVED] PTG as source to start ADC conversion

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
alan



Joined: 12 Nov 2012
Posts: 357
Location: South Africa

View user's profile Send private message

[SOLVED] PTG as source to start ADC conversion
PostPosted: Fri May 09, 2014 4:46 am     Reply with quote

Goodday

dsPIC33EP32MC202
CCS 5.024

Anybody have any experience setting the PTG up.
If I debug the target with MPLABX and ICD3 it seems that the PTG are stepping by looking at the PTGQPTR, but I do not get the start to the ADC.

Here are code snippets to set up and program.

Routine to write to the PTG queue. All variables that start with __ have the format #word __PTGCST = getenv("SFR:PTGCST") //PTG Control/Status register

Code:

#define PTGCTRL  (0x0 << 0)
#define PTGWHI   (0x4 << 4)
#define PTGTRIG  (0x8 << 4)
#define PTGJMP   (0xA << 4)
#define PTGJMPC0 (0xC << 4)
#define PTGIRQ   (0x7 << 4)

void Write_PTG_Step(uint8_t command) {
  switch (__STEP_Counter) {
    case 0: __PTGQUE0 = command; break;
    case 1: __PTGQUE0 |= (command<<8); break;
    case 2: __PTGQUE1 = command; break;
    case 3: __PTGQUE1 |= (command<<8); break;
    case 4: __PTGQUE2 = command; break;
    case 5: __PTGQUE2 |= (command<<8); break;
    case 6: __PTGQUE3 = command; break;
    case 7: __PTGQUE3 |= (command<<8); break;
    case 8: __PTGQUE4 = command; break;
    case 9: __PTGQUE4 |= (command<<8); break;
    case 10: __PTGQUE5 = command; break;
    case 11: __PTGQUE5 |= (command<<8); break;
    case 12: __PTGQUE6 = command; break;
    case 13: __PTGQUE6 |= (command<<8); break;
    case 14: __PTGQUE7 = command; break;
    case 15: __PTGQUE7 |= (command<<8); break;
  }
  __STEP_Counter++;
}

Routine that get's called once from main()
Code:

uint8_t __STEP_Counter;

void Periodic_ADC() {
  __PTGCST = 0x0000; //Disable Module
  __STEP_Counter = 0; //Reset commands in PTG Queue to 0
  __PTGQPTR = 0;
  __PTGCON = 0x3F00; //Clock source are Fosc and divide by 32
  __PTGBTE = 0x8000;//With broadcast trig will assert PTGO15 which is for ADC trig
  __PTGT1LIM = 0xF424; //25ms Timer when called
  //Write STEPS to Buffer
  Write_PTG_Step(PTGTRIG | 0x0f); //Send a PTGO15 trig which are one for the ADC
  Write_PTG_Step(PTGCTRL | 9); //Start and wait for the PTG Timer1 to match
  Write_PTG_Step(PTGTRIG | 0x0f); //Send a PTGO15 trig which are one for the ADC
  Write_PTG_Step(PTGCTRL | 9); //Start and wait for the PTG Timer1 to match
  Write_PTG_Step(PTGCTRL | 9); //Start and wait for the PTG Timer1 to match
  Write_PTG_Step(PTGCTRL | 0x0f); //Send a broadcast trigger PTGBTE
  Write_PTG_Step(PTGCTRL | 9); //Start and wait for the PTG Timer1 to match
  Write_PTG_Step(PTGCTRL | 9); //Start and wait for the PTG Timer1 to match
  Write_PTG_Step(PTGCTRL | 9); //Start and wait for the PTG Timer1 to match
                               //the PTGT1LIM register
Write_PTG_Step(PTGJMP | 0);  //Jump back to STEP0
  __PTGCST = 0x8000;
  __PTGCST = 0x8080;
}


This is the ADC setup. I had to manipulate the registers as I can't find a option in CCS to set the trigger to PTGO15
Frequency is set as 80MHz with FRC
Code:

  setup_adc(ADC_CLOCK_DIV_2);
  setup_adc_ports(sAN0 | sAN1, VSS_VDD );
  set_adc_channel(0);
  //Setup ADC to allow for PTG trig
  AD1CON1 &= 0x7f0f;  //Switch module off and reset sample clock select bits
  AD1CON1 |= 0x00D0; //PTGO15 primary trigger to start conversion
  AD1CON3 &= 0x00ff;
  AD1CON1 |= 0x8000;  //Switch module on
  enable_interrupts(INT_ADC1);
 
  enable_interrupts(INT_SPI1);
  enable_interrupts(INTR_GLOBAL);

and finally
Code:

#INT_ADC1
void adc_ready(void) {
  VTemp = read_adc(ADC_READ_ONLY);
  output_toggle(LED);
}


EDIT:
Needed to set the ASAM: ADC Sample Auto-Start as well thus
Code:

AD1CON1 |= 0x00D4; //PTGO15 primary trigger to start conversion


Thanks to all who had a look
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group