Hi,
I got it, I have to remove ADCON0, just use ADCON1 = 15.
Thanks for your precious time, and "Thank GOD for PBP forum"
Next stop is to make this chip as usb cdc to pass the data to pc...
regards,
tacbanon
Hi,
I got it, I have to remove ADCON0, just use ADCON1 = 15.
Thanks for your precious time, and "Thank GOD for PBP forum"
Next stop is to make this chip as usb cdc to pass the data to pc...
regards,
tacbanon
Last edited by tacbanon; - 6th October 2011 at 01:47.
Hi, now I'm trying to create a usb cdc together with the reading pulse code.
But I got this message "USB device not recognize". What could be causing this problem?Code:asm ;__CONFIG _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L __CONFIG _CONFIG1L, _PLLDIV_2_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L __CONFIG _CONFIG1H, _FOSC_XTPLL_XT_1H & _FCMEN_OFF_1H & _IESO_OFF_1H ; ; ; Oscillator Switchover mode disabled ; ; Fail-Safe Clock Monitor disabled ; XT oscillator, PLL enabled, XT used by USB __CONFIG _CONFIG2L, _PWRT_ON_2L & _BOR_ON_2L & _BORV_2_2L & _VREGEN_ON_2L __CONFIG _CONFIG2H, _WDT_OFF_2H __CONFIG _CONFIG3H, _MCLRE_ON_3H & _LPT1OSC_OFF_3H & _PBADEN_OFF_3H & _CCP2MX_ON_3H __CONFIG _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _ICPRT_OFF_4L & _XINST_OFF_4L & _DEBUG_OFF_4L endasm DEFINE OSC 48 DEFINE LCD_DREG PORTB DEFINE LCD_DBIT 0 DEFINE LCD_EREG PORTB DEFINE LCD_EBIT 5 DEFINE LCD_RSREG PORTB DEFINE LCD_RSBIT 4 DEFINE LCD_BITS 4 DEFINE LCD_LINES 2 DEFINE LCD_COMMANDUS 2000 DEFINE LCD_DATAUS 50 PAUSE 100 Include "cdc_desc.bas" ' Include the HID descriptors buffer Var Byte[16] Cnt VAR BYTE Cnt = 16 TRISA.4 = 1 ' RA4/T0CKI = input to TMR0 counter TRISA.0 = 0 ' RA0 = output for LED CMCON = 7 ' All digital ADCON1 = 001111 ' A/D converter off ' increment on low-to-high transitions T0CON = 111000 USBInit ' Initialize USART i var byte i=0 ' Lcdout $fe, 128, "Counters: ", #i pause 20 Main: TMR0L = 0 ' Clear TMR0 count before start USBService ' Service USB regularly Loop1: WHILE TMR0L = 0 ' Wait for high-to-low transition WEND ' on RA4/T0CKI pause 10 PORTB.0 = 1 ' LED on to indicate transition seen i=i+1 ' Clear screen buffer = i Lcdout $fe, 128, "Counter: ", #i 'PAUSE 30 PORTB.0 = 0 ' LED off USBService USBOut 3, Buffer, cnt, Main END
regards,
tacbanon
Last edited by tacbanon; - 6th October 2011 at 02:58.
Hi,
I hope someone else will chime in and try to help you because I've never used USB and don't know what the usual culprits are. Only advice I can give is to look at other examples and compare. Perhaps start with a working example and then add your counting code in "on top".
/Henrik.
Okay thanks for the advice Henrik
regards,
tacbanon
Hi everyone, now the usb device is recognized and its in Port COM2. My only problem is that my pulse counter variable i is reseting back to zero when a pulse(acctually I'm using a button on RA4 to simulate the pulse) is detected. In the code I did not yet insert the command "USBOut 3, buffer, cnt, Main" to send to pc.
I appreciate any help...Code:asm ;__CONFIG _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L __CONFIG _CONFIG1L, _PLLDIV_2_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L __CONFIG _CONFIG1H, _FOSC_XTPLL_XT_1H & _FCMEN_OFF_1H & _IESO_OFF_1H ; ; ; Oscillator Switchover mode disabled ; ; Fail-Safe Clock Monitor disabled ; XT oscillator, PLL enabled, XT used by USB __CONFIG _CONFIG2L, _PWRT_ON_2L & _BOR_ON_2L & _BORV_2_2L & _VREGEN_ON_2L __CONFIG _CONFIG2H, _WDT_OFF_2H __CONFIG _CONFIG3H, _MCLRE_ON_3H & _LPT1OSC_OFF_3H & _PBADEN_OFF_3H & _CCP2MX_ON_3H __CONFIG _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _ICPRT_OFF_4L & _XINST_OFF_4L & _DEBUG_OFF_4L endasm DEFINE OSC 48 DEFINE LCD_DREG PORTB DEFINE LCD_DBIT 0 DEFINE LCD_EREG PORTB DEFINE LCD_EBIT 5 DEFINE LCD_RSREG PORTB DEFINE LCD_RSBIT 4 DEFINE LCD_BITS 4 DEFINE LCD_LINES 2 DEFINE LCD_COMMANDUS 2000 DEFINE LCD_DATAUS 50 PAUSE 100 Include "cdc_desc.bas" ' Include the HID descriptors buffer Var Byte[16] Cnt VAR BYTE Cnt = 2 TRISA.4 = 1 ' RA4/T0CKI = input to TMR0 counter TRISA.0 = 0 ' RA0 = output for LED CMCON = 7 ' All digital ADCON1 = 001111 ' A/D converter off 'If you prefer, then increment on low-to-high transitions T0CON = 111000 USBInit ' Initialize USART i var byte i=0 ' Assign prescaler to WDT for 1:1 prescale on TMR0 ' TMR0 clock will be from your external input on RA4/T0CKI ' Increment on high-to-low transitions ' Lcdout $fe, 128, "Counter: ", #i 'pause 20 Main: USBService ' Must service USB regularly TMR0L = 0 ' Clear TMR0 count before start Loop1: WHILE TMR0L = 0 ' Wait for high-to-low transition USBService WEND ' on RA4/T0CKI pause 5 PORTB.0 = 1 ' LED on to indicate transition seen i=i+1 ' increment i Lcdout $fe, 128, "Counter: ", #i USBService PORTB.0 = 0 ' LED off
thanks in advance,
tacbanon
Last edited by tacbanon; - 6th October 2011 at 13:12.
When you enter the Loop1 routine you sit at the WHILE-WEND loop waiting for a pulse. When a pulse comes along you run thru the rest of the routine and finally pull PortB.0 low....then what happens?
There's no GOTO or END or anything after the Loop1 routine so the program will continue and continue and continue thru the (empty) codespace untill it reaches the end, then it'll wrap around and start over at the beginning and what happens there? Yep - you reset the count (i = 0) ;-)
By the way, you're now incrementing and displaying the i variable and not the TMR0 count but I guess that's intentional for now?
/Henrik.
Hi, yes your'e right Henrik "Goto Main" was all it need.
I think TMR0 and variable i are the same but only not reseting to zero, and I need it for visual.By the way, you're now incrementing and displaying the i variable and not the TMR0 count but I guess that's intentional for now?
I hope they can allow me here to continue, because I'm planning to incorporate an SD card module to hold the number of coins.
regards,
tacbanon
Bookmarks