pic pascal

Status
Not open for further replies.

williB

New Member
been doing PIC pascal programming
it is sooo much fun
i used mikroElektronika Pascal compiler
to read an analog voltage and set the pwm duty cycle ,and it worked !!
it has a LOT of built in routines
spi , I2c, ethernet , serial eeprom , list goes on and on!

Code:
program pwm_test_me2;
// program uses AN3 for Vref+ and AN2 for Vref- and AN0 for analog input
// and RC2 as pwm out on a 16F877A
// if you want to just connect AN3 to +5v and AN2 to ground it also will work
// but i think it is more usefull to have the option of using different references.
// because your maximum voltage that you may want to measure might only be +0.6V.
var temp_res : word;
    result : byte;

begin
  TRISA  := $FF;          // PORTA is input
  TRISC  := $FB;          // Initialize PORTC
  ADCON0 := $80;
  ADCON1 := $8F;          // Configure analog inputs and Vref


  Pwm_Init(19000);        // Initialize PWM module, freq = 19kHz.
  Pwm_Start;              // Start PWM


  while true do
  begin
    temp_res := Adc_Read(0); // put 10bit adc output into 16 bit word
    result := word(temp_res shr 2);  // shift 10bits right and store the eight bits into result
    Pwm_Change_Duty(result);  // Change duty ratio
  end;
end.
edit :
i thought i changed the comment in the pwm init routine to 19khz
i guess not..
 
Last edited:
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…