Jump to content

ra68gi

EstablishedMember
  • Content Count

    229
  • Joined

  • Last visited

Everything posted by ra68gi

  1. Tim, If u need to connect more than one LCD to ur mico connect them in parallel & multiplex them using some thing like using chip-select pin. Only one driver file can be used. May be u need to write ur own driver to support parallel devices working on different i/o pins. Most spi device will have chip-select pin. connect all devices in parallel(in, out & clk)& use different i/o pins for multiplexing the chip-select pin. Regards Raghunathan.P
  2. Hi, Have u not tried the picpack lib(pic_serial.c)? I tried it with 2550 & it works. Its such a waste of time trying to make a virtual serial port from ur usb device. USB is used for hi speed communication & u can make HID class device thro' which u can transfer data at a rate of 40-50 characters per millisecond. Sending variables from pic to PC is so easy using the HIDMAKER tools from tracesystem. try this out... http://tracesystemsinc.com/all-usb-product...ucts-alias.html Regards Raghunathan.P Edit : Sorry Harris I did'nt realise this was a very old thread.
  3. Long time ago I had asked Dr.Bob(Robert Miller) of Trace Systems if they could integrate BoostC compiler. I think Pavel & Dave should decide on this. HIDMAKER32 is shortly expected & they will support most USB microcontrollers from the 8bit to 32bit device. Regards Raghunathan.
  4. Hi, for all those who find USB difficult can try a simpler way of implimenting USB in ur PIC projects. http://tracesystemsinc.com/all-usb-product...ucts-alias.html Dave & Pavel, it will be nice if BoostC can be integrated in HID maker. Regards Raghunathan.P
  5. Hi Joli, acquiring 24bit signed data & storing it in 32bit signed can be a bit confusing. My approach is like this.. First I test if its MSB(24bit signed) is a 1. If its 1 then its a signed data. I store the rest of the bits in our normal 32bit(long) unsigned type. Then on the long data I do a 2's compiliment. finally to get the signed 32 bit data, I multiply it with -1. Here is an example done on 18bits of data. The rest of the adc bits where purposefully truncated. u can modify the code for 24bit signed. unsigned long adc_counter, adc_counter1; signed long adc_buff1; if(adc_digit_sign_flag==1) //If the MSB of the 24bit signed data is a 1 then..do 2's compliments. { adc_counter1 = adc_counter; adc_counter1 = ~ adc_counter1; // 1's compliment. adc_counter1 = adc_counter1 & 0x003FFFF; // 0x003ffff;0b00000000000000111111111111111111;rest of the bits other than the bits we use must be // forced to zero. adc_counter1 += 1; // 2's compliment. } if( adc_digit_sign_flag == 1) // set a flag for MSB of the 24bit signed data. convert it into 32bit signed l_adc_buff1 if the flag is 1. { adc_buff1 = (-1)* adc_counter1; } I hope the above code can help u come out with a method of storing 24bit signed data. Regards Raghunathan.P
  6. 24 bit floats ?? Regards Dave Some ADCs store the adc results (24bit) in signed 2s compliment format. The datas are usually sent out via SPI. In such case a it can be a little helpful if we could directly load the value into such data types. Regards Raghunathan.P
  7. Hi Dave, When can we expect the next release of Source Boost IDE? Will the the above device be included in the target device drop down menu? I have not yet down loaded the beta2 version. Regards Raghunathan.P
  8. Dear sir, Please allow me to differ with you here. I think its the time which becomes half of the total ccp. So the freq would be double. Please correct me if I am wrong as I am a novoice. I still think that the CCPR1L's value must be half of the value of period register value in order to get a 50% duty cycle. Am I wrong? Further more I was just wondering whether the ECCP o/p keeps on running in background, allowing me to do any other jobs with my pic (like continously monitering the adc channel, making some ports high or low etc?) Thanks for your efforts and support Regards Shree Some times things defy our reasoning so I suggest u program a device & see the wave forms on an oscilloscope. Regards Raghunathan.P
  9. Shree, The PWM output at the ccp pin is designed for 100hz and the two out of phase pulse generated in the ISR will have half the freq of the ccp pin ie.50hz. Now the pulse out at the ccp pin can have 0 to 100 % ON time by loading the ccpr1l & ccpr1h. This ccp pin pulse has to be ANDed with the 50hz pulse generated in the ISR. Then As the duty cycle changes from 0 to 100% in the ccp pin the 50hz pulse in ISR(RB0 & RB1) will vary from 0 to 50%. A graphical representation will make things better to understand. Try if u can figure out from the above information. Regards Raghunathan.P
  10. Hi Shree, I don't know about your code, but I can tell u how the PWM module works. First there are three important registers associated with it. they are 1) tmr2 or timer2 register 2) pr2 register also called the period register. 3) ccpr1l & ccpr1h which holds the 10bit duty cycle value. a)PWM generates a square wave form output at the ccp pin. b)Any square wave form has an ON time & OFF time. c) The ON time is called the duty or duty cycle. d) One ON time plus one OFF time is called the period or T. Frequency of the wave form is f = 1 / T . e) The ON time is decided by the duty cycle value(10bit ccpril & ccp1con<5:4>) register. f) The Period or frequency is controlled by the pr2 value. How it works? Two comparators keep comparing the pr2 register value & duty cycle value with timer2(tmr2) value which is free running. When the tmr2 value equals pr2 value the ccp pin is made high & next when it reaches ccpr1l + ccp1con<5:4> value it makes the pin low. Also when tmr2 value equals pr2 value a flag is set & the tmr2 is reset to zero. You can enable the interrupt bit TMR2IE. You can try to change the duty cycle value in the ISR. You can also toggle your i/o pins in the ISR. Use this sample code on PIC16F72 or similar. Use external RC. R value is 10k & C value is 68pf. You can see the output in ccp pin. Also two out of phase 50hz pulse in RB0 & RB1. #include <system.h> // Set clock frequency to 1MHz. #pragma CLOCK_FREQ 1000000 //set configuration fuse. #pragma DATA _CONFIG, _RC_OSC & _WDT_OFF & _CP_OFF & _PWRTE_OFF int duty_cycle; //global variable /*Interrupt service routine (ISR).On timer2 interrupt, program will jump to this code location. */ void interrupt( void ) { char pulse; /*generate two 50hz 180 degree out of phase pulses & externally AND it with the 100Hz pwm pin to get a modulated 50Hz to drive mosfets connected to a transformer in a push-pull configuration. A/D conversion of the the output voltage can act as feed back to adjust the duty-cycle ( not yet implemented in this code). */ pulse = portb; pulse.0 = ~ pulse.0; pulse.1 = ~ pulse.1; portb = pulse; pir1.1=0; //clear TMR2 to pr2 match interrupt flag } void load_duty_cycle(void) { ccpr1l.7 = duty_cycle.9; ccpr1l.6 = duty_cycle.8; ccpr1l.5 = duty_cycle.7; ccpr1l.4 = duty_cycle.6; ccpr1l.3 = duty_cycle.5; ccpr1l.2 = duty_cycle.4; ccpr1l.1 = duty_cycle.3; ccpr1l.0 = duty_cycle.2; ccp1con.5 = duty_cycle.1; ccp1con.4 = duty_cycle.0; } // The main code configures the pwm registers void main() { trisa = 255; trisb = 0; //configure port B as output trisc = 0; // portc as out put portb = 1; //set port B to 1 portc = 0; //clear portc // enable interrupts intcon.6=1; //enable peripheral interrupt intcon.7=1; //enable global interrupt pie1.1=1; //tmr2 to pr2 match interrupt //configure the ccp1con register to enable PWM module. /*ccpxm3:ccpxm0: mode select bits<3:0> 11xx = for PWM mode. */ ccp1con=0b00001100; // //PWM period=[(PR2)+1]*4*Tosc*(TMR2 prescaler value) /*our pmw period is 10ms(100Hz),Tosc is 1/1000,000Hz & prescaler is 16.For which PR2+1 works out to 156.25. Lets round it to 156 & make PR2 to 155. */ //load the period value into pr2 register. pr2 = 155; /*timer2 control register we have selected bit6-3...(0000) 1:1 for post scaler bit2.....(1) timer2 on bit1-0...(11) prescaler is 16 */ t2con = 0b00000111; /*PWM duty cycle = (ccpr1l:ccp1con<5:4>)*Tosc*(TMR2 prescaler value) Here i have taken 2ms as an example value for duty cycle, Tosc & pre- scaler are same as above.We will get 10 bit values when we work with larger duty cycle but for our example we get the value as 125. */ //load the duty cycle values while( 1 ) { int b0; for(b0=1;b0<563;b0++) { duty_cycle = b0; load_duty_cycle(); delay_ms(9); } } } hope this helps Regards Raghunathan.P
  11. I think we don't have. You can make your own function. I have a sample code made long back. see if it can help u. Its made for PIC16F72, 1mhz RC clock. #include <system.h> // Set clock frequency to 1MHz. #pragma CLOCK_FREQ 1000000 //set configuration fuse. #pragma DATA _CONFIG, _RC_OSC & _WDT_OFF & _CP_OFF & _PWRTE_OFF int duty_cycle; //global variable /*Interrupt service routine (ISR).On timer2 interrupt, program will jump to this code location. */ void interrupt( void ) { char pulse; /*generate two 50hz 180 degree out of phase pulses & externally AND it with the 100Hz pwm pin to get a modulated 50Hz to drive mosfets connected to a transformer in a push-pull configuration. A/D conversion of the the output voltage can act as feed back to adjust the duty-cycle ( not yet implemented in this code). */ pulse = portb; pulse.0 = ~ pulse.0; pulse.1 = ~ pulse.1; portb = pulse; pir1.1=0; //clear TMR2 to pr2 match interrupt flag } void load_duty_cycle(void) { ccpr1l.7 = duty_cycle.9; ccpr1l.6 = duty_cycle.8; ccpr1l.5 = duty_cycle.7; ccpr1l.4 = duty_cycle.6; ccpr1l.3 = duty_cycle.5; ccpr1l.2 = duty_cycle.4; ccpr1l.1 = duty_cycle.3; ccpr1l.0 = duty_cycle.2; ccp1con.5 = duty_cycle.1; ccp1con.4 = duty_cycle.0; } // The main code configures the pwm registers void main() { trisa = 255; trisb = 0; //configure port B as output trisc = 0; // portc as out put portb = 1; //set port B to 1 portc = 0; //clear portc // enable interrupts intcon.6=1; //enable peripheral interrupt intcon.7=1; //enable global interrupt pie1.1=1; //tmr2 to pr2 match interrupt //configure the ccp1con register to enable PWM module. /*ccpxm3:ccpxm0: mode select bits<3:0> 11xx = for PWM mode. */ ccp1con=0b00001100; // //PWM period=[(PR2)+1]*4*Tosc*(TMR2 prescaler value) /*our pmw period is 10ms(100Hz),Tosc is 1/1000,000Hz & prescaler is 16.For which PR2+1 works out to 156.25. Lets round it to 156 & make PR2 to 155. */ //load the period value into pr2 register. pr2 = 155; /*timer2 control register we have selected bit6-3...(0000) 1:1 for post scaler bit2.....(1) timer2 on bit1-0...(11) prescaler is 16 */ t2con = 0b00000111; /*PWM duty cycle = (ccpr1l:ccp1con<5:4>)*Tosc*(TMR2 prescaler value) Here i have taken 2ms as an example value for duty cycle, Tosc & pre- scaler are same as above.We will get 10 bit values when we work with larger duty cycle but for our example we get the value as 125. */ //load the duty cycle values while( 1 ) { int b0; for(b0=1;b0<563;b0++) { duty_cycle = b0; load_duty_cycle(); delay_ms(9); } } } Regards Raghunathan
  12. Well if they have a time/resource constraint, I would prefer they concentrate on getting a compiler for the 24bit device. Regards Raghunathan
  13. Thanks to Dave & Pavel, The 16F1937 is very attractively priced, so planning of using them in my new projects. Regards Raghunathan.
  14. Hi Dave, Do you intend to support the 16F193X series devices ? If so How soon? Regards Raghunathan.
  15. Hi, There are some issues when u have your argument as pointer. declare the pointer as char *n as in the above case.. signed long adc_deci ( char *n) { signed long m; m = 0; m += *n++; m += *n++ * 10; m += *n++ * 100; m += *n++ * 1000; m += *n++ * 10000; if(adc_sign_digit==0) { m = m*(-1); } return m; } I have a doubt here??? I think its ok to pass a string in the calling function & u need to check the null character as the terminator. Like the simple putc function void putc(unsigned char tx_char) { while(SSR0_TDRE == 0); TDR0 = tx_char; } void puts(char *source) { while (*source != 0) putc(*source++); } void main() { while(1) { puts("raghu"); } } But if u have a pointer as the argument in a function & u have a array to be passed in the call function, I think u need to write the call function this way adc_deci(&adc_bcd); // in the first example puts(&adc_bcd); //2nd example Reynard, correct me if I am wrong. Regards Raghunathan.
  16. bit adc_sign_digit; signed long adc_deci (unsigned char n[]) { signed long m; m = 0; m += n[0]; m += n[1] * 10; m += n[2] * 100; m += n[3] * 1000; m += n[4] * 10000; if(adc_sign_digit==0) { m = m*(-1); } return m; } void main() { unsigned char adc_bcd[5]; while(1) { if (portd.6 == 0) //if tare. { tare_value = adc_deci(adc_bcd); } } } Regards Raghunathan
  17. Hi Reynard, Its not called preload register but period register. timer2 is used for the pwm module & its value is compared with PR2 register and the duty cycle value( stored in a crazy way in the PIC). One can activate the interrupt for tmr2 PR2 match. Regards Raghu.
  18. Hi Trossin, I disagree that you can't get accurate timing with tmr0. As of the crystal error is concerned you may be right. But every one uses a crystal. The sample code I had given in the thread "programming pic micro using boostc" is correct. I have checked it up using mplab stopwatch. And I have used it as a real time clock & it works fine. Build the program in mplab sim, make a break point in the first line in the ISR, reset the stop watch on the first interrupt & run it several times & you will see that the stop watch show 250us every time. The code tmr0 +=9 ; is all you need to add in the isr. Its a very simple code & it works. Shree, the error u might have got could be because u did'nt reset the timer at the first interrupt. The first interrupt will have a over head of the initial port setting & register config settings. Where u don't need to measure time intervals of 250us, Pommie's code is better because your code doesn't get interrupted often. Regards Raghunathan.
  19. Hey Sree, Once you enter into a while(1) loop in the main, don't get out off it. Why do you go back to initializing the ports. I would suggest not to use goto. If u are using flags then there is no need to use goto. Regards Raghunathan
  20. Hello Mr. Raghunathan, If you see the code, the interrupt and eeprom functions never occur toeghter. Besides there is always 1 second more in every minute. I dont know why. Regards Shree Well, if the eeprom write & read are not called while your timer/ interrupt is activated, there could be some other problem. you can probably check the timing on the mplab simulator using stop watch. Make your global variable dist as signed int. since you keep decrementing its value in the ISR. it may take negative value. use while(dist>0) or while(dist>-1) Regards Raghunathan.
  21. Hi Sree, I didn't have time to go through your code. I think the eeprom read & write functions disable the interrupts while writing & reading. May be that could be one reason why your timing is not accurate. Regards Raghunathan.
  22. Currently I am using the STX command as a qualifier, then placing the data into my array after that. I really don't think that part is my issue now, but I will note that and try it if the crystal doesn't provide any improvements. Thank you for your suggestions. I would suggest u use the builtin function of the sourceboost to begin with. Some times I do face problem with data parsing. The data stream should be sent at the same rate( mind u this is not the baud rate). If there is a change in the data stream rate( say from 10characters/s to 20char/sec) then chances are there that some of the datas don't get received properly. For which I introduce a minimum delay between character equal to (10 * (1/baudrate)), assuming 10bit length data. Regards Raghunathan.
  23. hi, for your serial receive program, u can use the space as the qualifier & start loading the other digits in an array. The size of the array depends on the data digits lenght. try placing full-load to the indicator determine the data length. I thought it should display 00001828 on the hyper. Regards Raghunathan.
  24. Hi, I suppose u can connect a load cell to your indicator. connect it & see if the count value changes on the hyper-term when you press the load-cell. Right now what we see on the screen must be just raw counts. we need to config & calibrate the device. I probably would require the whole data sheet to do that. regards Raghunathan.
×
×
  • Create New...